0% found this document useful (0 votes)
41 views2 pages

Problem 1:: Twodimensionalshape (Double D1, Double D2)

The document describes class hierarchies for two-dimensional shapes. It defines classes for TwoDimensionalShape, Circle, and Square. It then asks the reader to: 1. Create objects of each class and access members through a TwoDimensionalShape reference. 2. Make TwoDimensionalShape abstract by making its area() method abstract, then repeat step 1. It then adds a parent Shape class and asks the reader to: 3. Update the classes to include Shape as a parent of TwoDimensionalShape. 4. Access subclass methods through a Shape reference and test overridden method behavior. The document provides class structure definitions and tasks to demonstrate polymorphism through inheritance and references.

Uploaded by

Rakib Ahsan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views2 pages

Problem 1:: Twodimensionalshape (Double D1, Double D2)

The document describes class hierarchies for two-dimensional shapes. It defines classes for TwoDimensionalShape, Circle, and Square. It then asks the reader to: 1. Create objects of each class and access members through a TwoDimensionalShape reference. 2. Make TwoDimensionalShape abstract by making its area() method abstract, then repeat step 1. It then adds a parent Shape class and asks the reader to: 3. Update the classes to include Shape as a parent of TwoDimensionalShape. 4. Access subclass methods through a Shape reference and test overridden method behavior. The document provides class structure definitions and tasks to demonstrate polymorphism through inheritance and references.

Uploaded by

Rakib Ahsan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Problem 1:

Consider the following class hierarchy:



Class TwoDimensionalShape:
(1) Two private member dim1, dim2 (double type)
(2) Constructor TwoDimensionalShape (double d1, double d2)
(3) Two setDim(double d) to set values of d1 and d2.
(4) Two getDim(double d) to get values of dim1, dim2.
(5) Double area() to display some message.
(6) String getName() to print Two Dimensional Object.
Class Circle (subclass of TwoDimensionalShape):
(1) Constructor Circle (double radius)
(2) setRadius() method
(3) getRadius() method
(4) Double area() to calculate area of circle.
(5) String getName() to print Circle
Class Square (subclass of TwoDimensionalShape):
(6) Constructor Square (double side)
(7) setSide() method
(8) getSide() method
(9) Double area() to calculate area of square.
(10) String getName() to print Square

Now perform the following operations:
1. Create an object of each class to access the data and method members.
2. Create a reference of TwoDimensionalShape class and access Circle and Square Class.
3. Make TwoDimensionalShape class abstract class by making Double area() method abstract.
4. Repeat Step 2.




Problem 2:
Now consider the following hierarchy that will add a parent Shape of TwoDimensionalShape.



Class Shape:
(1) Two private member x and y (int type)
(2) Constructor Shape (int x, int y)
(3) setX() and setY().
(4) getX() and getY().
(5) Abstract String getName();
Now perform the following operations:
(1) Make necessary changes to all classes as Shape is added as the parent of
TwoDimensionalShape.
(2) Create a reference of Shape class and access all the subclasses method members.
(3) Test for all overridden methods. Try to inactivate overridden methods of some classes and see
what will happen.
Problem 3:
Based on the experiences of Problem 1 and 2 now develop necessary code for the following hierarchy:

You might also like