SlideShare a Scribd company logo
1 of 4
Download to read offline
LAB 9+10: INHERITANCE, INTERFACE AND POLYMORPHISM
Objectives:
 Understanding Unified Modeling Language (UML)
 Applying Inheritance mechanism (is-a relation)
 Understanding and using super keyword
 Using Abstract classes and methods
 Applying methods overriding mechanism
 Interface
 Polymorphism
Practice – Shape hierarchy UML:
Classes’ description:
Point class members:
 Fields: x and y as integers
 Methods:
o Default and parametrized constructors
o Setters and getters
o toString(): returns a string representation of the class attributes values; (i.e. (100,200))
 Shape is an abstract class with the following members:
o Fields:
 point as Point
 count as static integer
o Methods:
 Default and parametrized constructor
 Setters and getters
 toString(): returns a string representation of the class attributes values
 Circle class – extends Shape class – members:
o Fields:
 Inherited fields from shape class
 radius as double
 count: as static integer
o Methods:
 Default and parametrized constructor
 Setters and getters
 diameter(): returns the diameter of the circle
 toString(): returns a string representation of the circle attributes values
Ex: Center: (100,150), Radius: 15.5
 Rectangle class – extends shape class- members:
o Fields:
 Inherited fields from shape class
 Width and height as doubles
 count: as static integer
o Methods:
 Default and parametrized constructor
 Setters and getters
 toString(): returns a string representation of the rectangle attributes values
Ex: starting point: (100,150), width: 20, height: 56.25
 Square class – extends Rectangle class- members:
o Fields:
 Inherited fields from rectangle class
 count: as static integer
o Methods:
 Default and parametrized constructor
 Setters and getters
 toString(): returns a string representation of the square attributes values
Ex: starting point: (100,150), edge: 20
Note: the static member count declared in each class used to store number of objects created from that
class and its value shared among all the objects of the same class
Design a JFrame class as figure below, which allows the user to:
In the input tab:
 add circles, rectangles and squares to ArrayList of type Shape, and show them on a
corresponding JList as the figure below
 display number of objects created of each type
in the preview tab:
 select a list member to print that shape area and perimeter on a message dialog; if the shape is
circle then print its diameter also.
Application frame:
Using Polymorphism:
Replace the preview tab with following tab to handle the shapes using the polymorphism approach by
creating an Array (or ArrayList) of the Shape class (superclass) and add object references of the
subclasses.
In this tab all the shapes are shown in the same list, then when:
 select a list member to print that shape area and perimeter on a message dialog; if the shape is
circle then print its diameter also.
 Click:
o edit shape button will asks the user to enter new values for the selected shape
attributes through input dialogs and sets these values to it
o remove shape button will remove the selected shape from the array list
o find similar shapes button show all the similar shapes in a message dialog

More Related Content

Similar to Lab_910.pdf

14 class design (1)
14 class design (1)14 class design (1)
14 class design (1)Satyam Gupta
 
Basic Graphics in Java
Basic Graphics in JavaBasic Graphics in Java
Basic Graphics in JavaPrakash Kumar
 
Class program and uml in c++
Class program and uml in c++Class program and uml in c++
Class program and uml in c++Osama Al-Mohaia
 
Descriptions of class diagrams in software
Descriptions of class diagrams in softwareDescriptions of class diagrams in software
Descriptions of class diagrams in softwaressuser9d62d6
 
Python Strings Format
Python Strings FormatPython Strings Format
Python Strings FormatMr Examples
 
Please make the complete program, Distinguish between header files a.pdf
Please make the complete program, Distinguish between header files a.pdfPlease make the complete program, Distinguish between header files a.pdf
Please make the complete program, Distinguish between header files a.pdfSALES97
 
Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Abou Bakr Ashraf
 
Write a new version of the area calculation program that makes use of.docx
 Write a new version of the area calculation program that makes use of.docx Write a new version of the area calculation program that makes use of.docx
Write a new version of the area calculation program that makes use of.docxajoy21
 
Ecs40 winter 2017 homework 3
Ecs40 winter 2017 homework 3Ecs40 winter 2017 homework 3
Ecs40 winter 2017 homework 3JenniferBall44
 

Similar to Lab_910.pdf (20)

14 class design (1)
14 class design (1)14 class design (1)
14 class design (1)
 
14 class design
14 class design14 class design
14 class design
 
Basic Graphics in Java
Basic Graphics in JavaBasic Graphics in Java
Basic Graphics in Java
 
Intake 38 6
Intake 38 6Intake 38 6
Intake 38 6
 
Class program and uml in c++
Class program and uml in c++Class program and uml in c++
Class program and uml in c++
 
Descriptions of class diagrams in software
Descriptions of class diagrams in softwareDescriptions of class diagrams in software
Descriptions of class diagrams in software
 
Getters_And_Setters.pptx
Getters_And_Setters.pptxGetters_And_Setters.pptx
Getters_And_Setters.pptx
 
Autocad Commands.pdf
Autocad Commands.pdfAutocad Commands.pdf
Autocad Commands.pdf
 
F# Console class
F# Console classF# Console class
F# Console class
 
PPT
PPTPPT
PPT
 
Powerpoint school
Powerpoint schoolPowerpoint school
Powerpoint school
 
What's new in Calc and Chart
What's new in Calc and ChartWhat's new in Calc and Chart
What's new in Calc and Chart
 
Python Strings Format
Python Strings FormatPython Strings Format
Python Strings Format
 
Please make the complete program, Distinguish between header files a.pdf
Please make the complete program, Distinguish between header files a.pdfPlease make the complete program, Distinguish between header files a.pdf
Please make the complete program, Distinguish between header files a.pdf
 
Module03
Module03Module03
Module03
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
 
Powerpoint school
Powerpoint schoolPowerpoint school
Powerpoint school
 
Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Visula C# Programming Lecture 6
Visula C# Programming Lecture 6
 
Write a new version of the area calculation program that makes use of.docx
 Write a new version of the area calculation program that makes use of.docx Write a new version of the area calculation program that makes use of.docx
Write a new version of the area calculation program that makes use of.docx
 
Ecs40 winter 2017 homework 3
Ecs40 winter 2017 homework 3Ecs40 winter 2017 homework 3
Ecs40 winter 2017 homework 3
 

Recently uploaded

定制(Waikato毕业证书)新西兰怀卡托大学毕业证成绩单原版一比一
定制(Waikato毕业证书)新西兰怀卡托大学毕业证成绩单原版一比一定制(Waikato毕业证书)新西兰怀卡托大学毕业证成绩单原版一比一
定制(Waikato毕业证书)新西兰怀卡托大学毕业证成绩单原版一比一Fs
 
阿德莱德大学本科毕业证成绩单咨询(书英文硕士学位证)
阿德莱德大学本科毕业证成绩单咨询(书英文硕士学位证)阿德莱德大学本科毕业证成绩单咨询(书英文硕士学位证)
阿德莱德大学本科毕业证成绩单咨询(书英文硕士学位证)obuhobo
 
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...Suhani Kapoor
 
加利福尼亚大学伯克利分校硕士毕业证成绩单(价格咨询)学位证书pdf
加利福尼亚大学伯克利分校硕士毕业证成绩单(价格咨询)学位证书pdf加利福尼亚大学伯克利分校硕士毕业证成绩单(价格咨询)学位证书pdf
加利福尼亚大学伯克利分校硕士毕业证成绩单(价格咨询)学位证书pdfobuhobo
 
Gurgaon Call Girls: Free Delivery 24x7 at Your Doorstep G.G.N = 8377087607
Gurgaon Call Girls: Free Delivery 24x7 at Your Doorstep G.G.N = 8377087607Gurgaon Call Girls: Free Delivery 24x7 at Your Doorstep G.G.N = 8377087607
Gurgaon Call Girls: Free Delivery 24x7 at Your Doorstep G.G.N = 8377087607dollysharma2066
 
定制(UQ毕业证书)澳洲昆士兰大学毕业证成绩单原版一比一
定制(UQ毕业证书)澳洲昆士兰大学毕业证成绩单原版一比一定制(UQ毕业证书)澳洲昆士兰大学毕业证成绩单原版一比一
定制(UQ毕业证书)澳洲昆士兰大学毕业证成绩单原版一比一lvtagr7
 
Storytelling, Ethics and Workflow in Documentary Photography
Storytelling, Ethics and Workflow in Documentary PhotographyStorytelling, Ethics and Workflow in Documentary Photography
Storytelling, Ethics and Workflow in Documentary PhotographyOrtega Alikwe
 
How to Find the Best NEET Coaching in Indore (2).pdf
How to Find the Best NEET Coaching in Indore (2).pdfHow to Find the Best NEET Coaching in Indore (2).pdf
How to Find the Best NEET Coaching in Indore (2).pdfmayank158542
 
Call Girls Mukherjee Nagar Delhi reach out to us at ☎ 9711199012
Call Girls Mukherjee Nagar Delhi reach out to us at ☎ 9711199012Call Girls Mukherjee Nagar Delhi reach out to us at ☎ 9711199012
Call Girls Mukherjee Nagar Delhi reach out to us at ☎ 9711199012rehmti665
 
Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...
Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...
Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...shivangimorya083
 
NPPE STUDY GUIDE - NOV2021_study_104040.pdf
NPPE STUDY GUIDE - NOV2021_study_104040.pdfNPPE STUDY GUIDE - NOV2021_study_104040.pdf
NPPE STUDY GUIDE - NOV2021_study_104040.pdfDivyeshPatel234692
 
PM Job Search Council Info Session - PMI Silver Spring Chapter
PM Job Search Council Info Session - PMI Silver Spring ChapterPM Job Search Council Info Session - PMI Silver Spring Chapter
PM Job Search Council Info Session - PMI Silver Spring ChapterHector Del Castillo, CPM, CPMM
 
定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一
定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一
定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一2s3dgmej
 
VIP Call Girls Service Jamshedpur Aishwarya 8250192130 Independent Escort Ser...
VIP Call Girls Service Jamshedpur Aishwarya 8250192130 Independent Escort Ser...VIP Call Girls Service Jamshedpur Aishwarya 8250192130 Independent Escort Ser...
VIP Call Girls Service Jamshedpur Aishwarya 8250192130 Independent Escort Ser...Suhani Kapoor
 
Preventing and ending sexual harassment in the workplace.pptx
Preventing and ending sexual harassment in the workplace.pptxPreventing and ending sexual harassment in the workplace.pptx
Preventing and ending sexual harassment in the workplace.pptxGry Tina Tinde
 
原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证
原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证
原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证nhjeo1gg
 
VIP Russian Call Girls in Bhilai Deepika 8250192130 Independent Escort Servic...
VIP Russian Call Girls in Bhilai Deepika 8250192130 Independent Escort Servic...VIP Russian Call Girls in Bhilai Deepika 8250192130 Independent Escort Servic...
VIP Russian Call Girls in Bhilai Deepika 8250192130 Independent Escort Servic...Suhani Kapoor
 
VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...
VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...
VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...Suhani Kapoor
 

Recently uploaded (20)

定制(Waikato毕业证书)新西兰怀卡托大学毕业证成绩单原版一比一
定制(Waikato毕业证书)新西兰怀卡托大学毕业证成绩单原版一比一定制(Waikato毕业证书)新西兰怀卡托大学毕业证成绩单原版一比一
定制(Waikato毕业证书)新西兰怀卡托大学毕业证成绩单原版一比一
 
阿德莱德大学本科毕业证成绩单咨询(书英文硕士学位证)
阿德莱德大学本科毕业证成绩单咨询(书英文硕士学位证)阿德莱德大学本科毕业证成绩单咨询(书英文硕士学位证)
阿德莱德大学本科毕业证成绩单咨询(书英文硕士学位证)
 
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
 
加利福尼亚大学伯克利分校硕士毕业证成绩单(价格咨询)学位证书pdf
加利福尼亚大学伯克利分校硕士毕业证成绩单(价格咨询)学位证书pdf加利福尼亚大学伯克利分校硕士毕业证成绩单(价格咨询)学位证书pdf
加利福尼亚大学伯克利分校硕士毕业证成绩单(价格咨询)学位证书pdf
 
Gurgaon Call Girls: Free Delivery 24x7 at Your Doorstep G.G.N = 8377087607
Gurgaon Call Girls: Free Delivery 24x7 at Your Doorstep G.G.N = 8377087607Gurgaon Call Girls: Free Delivery 24x7 at Your Doorstep G.G.N = 8377087607
Gurgaon Call Girls: Free Delivery 24x7 at Your Doorstep G.G.N = 8377087607
 
定制(UQ毕业证书)澳洲昆士兰大学毕业证成绩单原版一比一
定制(UQ毕业证书)澳洲昆士兰大学毕业证成绩单原版一比一定制(UQ毕业证书)澳洲昆士兰大学毕业证成绩单原版一比一
定制(UQ毕业证书)澳洲昆士兰大学毕业证成绩单原版一比一
 
Storytelling, Ethics and Workflow in Documentary Photography
Storytelling, Ethics and Workflow in Documentary PhotographyStorytelling, Ethics and Workflow in Documentary Photography
Storytelling, Ethics and Workflow in Documentary Photography
 
How to Find the Best NEET Coaching in Indore (2).pdf
How to Find the Best NEET Coaching in Indore (2).pdfHow to Find the Best NEET Coaching in Indore (2).pdf
How to Find the Best NEET Coaching in Indore (2).pdf
 
Call Girls Mukherjee Nagar Delhi reach out to us at ☎ 9711199012
Call Girls Mukherjee Nagar Delhi reach out to us at ☎ 9711199012Call Girls Mukherjee Nagar Delhi reach out to us at ☎ 9711199012
Call Girls Mukherjee Nagar Delhi reach out to us at ☎ 9711199012
 
Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...
Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...
Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...
 
NPPE STUDY GUIDE - NOV2021_study_104040.pdf
NPPE STUDY GUIDE - NOV2021_study_104040.pdfNPPE STUDY GUIDE - NOV2021_study_104040.pdf
NPPE STUDY GUIDE - NOV2021_study_104040.pdf
 
PM Job Search Council Info Session - PMI Silver Spring Chapter
PM Job Search Council Info Session - PMI Silver Spring ChapterPM Job Search Council Info Session - PMI Silver Spring Chapter
PM Job Search Council Info Session - PMI Silver Spring Chapter
 
定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一
定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一
定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一
 
VIP Call Girls Service Jamshedpur Aishwarya 8250192130 Independent Escort Ser...
VIP Call Girls Service Jamshedpur Aishwarya 8250192130 Independent Escort Ser...VIP Call Girls Service Jamshedpur Aishwarya 8250192130 Independent Escort Ser...
VIP Call Girls Service Jamshedpur Aishwarya 8250192130 Independent Escort Ser...
 
Preventing and ending sexual harassment in the workplace.pptx
Preventing and ending sexual harassment in the workplace.pptxPreventing and ending sexual harassment in the workplace.pptx
Preventing and ending sexual harassment in the workplace.pptx
 
FULL ENJOY Call Girls In Gautam Nagar (Delhi) Call Us 9953056974
FULL ENJOY Call Girls In Gautam Nagar (Delhi) Call Us 9953056974FULL ENJOY Call Girls In Gautam Nagar (Delhi) Call Us 9953056974
FULL ENJOY Call Girls In Gautam Nagar (Delhi) Call Us 9953056974
 
原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证
原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证
原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证
 
VIP Russian Call Girls in Bhilai Deepika 8250192130 Independent Escort Servic...
VIP Russian Call Girls in Bhilai Deepika 8250192130 Independent Escort Servic...VIP Russian Call Girls in Bhilai Deepika 8250192130 Independent Escort Servic...
VIP Russian Call Girls in Bhilai Deepika 8250192130 Independent Escort Servic...
 
Young Call~Girl in Pragati Maidan New Delhi 8448380779 Full Enjoy Escort Service
Young Call~Girl in Pragati Maidan New Delhi 8448380779 Full Enjoy Escort ServiceYoung Call~Girl in Pragati Maidan New Delhi 8448380779 Full Enjoy Escort Service
Young Call~Girl in Pragati Maidan New Delhi 8448380779 Full Enjoy Escort Service
 
VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...
VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...
VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...
 

Lab_910.pdf

  • 1. LAB 9+10: INHERITANCE, INTERFACE AND POLYMORPHISM Objectives:  Understanding Unified Modeling Language (UML)  Applying Inheritance mechanism (is-a relation)  Understanding and using super keyword  Using Abstract classes and methods  Applying methods overriding mechanism  Interface  Polymorphism Practice – Shape hierarchy UML:
  • 2. Classes’ description: Point class members:  Fields: x and y as integers  Methods: o Default and parametrized constructors o Setters and getters o toString(): returns a string representation of the class attributes values; (i.e. (100,200))  Shape is an abstract class with the following members: o Fields:  point as Point  count as static integer o Methods:  Default and parametrized constructor  Setters and getters  toString(): returns a string representation of the class attributes values  Circle class – extends Shape class – members: o Fields:  Inherited fields from shape class  radius as double  count: as static integer o Methods:  Default and parametrized constructor  Setters and getters  diameter(): returns the diameter of the circle  toString(): returns a string representation of the circle attributes values Ex: Center: (100,150), Radius: 15.5  Rectangle class – extends shape class- members: o Fields:  Inherited fields from shape class  Width and height as doubles  count: as static integer o Methods:  Default and parametrized constructor  Setters and getters  toString(): returns a string representation of the rectangle attributes values Ex: starting point: (100,150), width: 20, height: 56.25  Square class – extends Rectangle class- members: o Fields:  Inherited fields from rectangle class  count: as static integer o Methods:  Default and parametrized constructor  Setters and getters  toString(): returns a string representation of the square attributes values Ex: starting point: (100,150), edge: 20
  • 3. Note: the static member count declared in each class used to store number of objects created from that class and its value shared among all the objects of the same class Design a JFrame class as figure below, which allows the user to: In the input tab:  add circles, rectangles and squares to ArrayList of type Shape, and show them on a corresponding JList as the figure below  display number of objects created of each type in the preview tab:  select a list member to print that shape area and perimeter on a message dialog; if the shape is circle then print its diameter also. Application frame:
  • 4. Using Polymorphism: Replace the preview tab with following tab to handle the shapes using the polymorphism approach by creating an Array (or ArrayList) of the Shape class (superclass) and add object references of the subclasses. In this tab all the shapes are shown in the same list, then when:  select a list member to print that shape area and perimeter on a message dialog; if the shape is circle then print its diameter also.  Click: o edit shape button will asks the user to enter new values for the selected shape attributes through input dialogs and sets these values to it o remove shape button will remove the selected shape from the array list o find similar shapes button show all the similar shapes in a message dialog