Question: Question 1. Write a program that defines a Shape class that demonstrates encapsulation by using private variables and public getters and setters. The class also

 Question 1. Write a program that defines a Shape class thatdemonstrates encapsulation by using private variables and public getters and setters. The

Question 1. Write a program that defines a Shape class that demonstrates encapsulation by using private variables and public getters and setters. The class also demonstrates polymorphism by having a draw() method that can be overridden in subclasses. The Rectangle and Circle classes inherit from the Shape class and demonstrate inheritance by having access to the variables and methods of the Shape class and also they override the draw() method. You are required to: i) Implement the inheritance hierarchy illustrated above. ii) In the main method, apply polymorphism by creating objects of Rectangle, Circle, and Shape and calling the 'draw' method on them with the same reference. iii) In the Shape class, create Area() methods that calculate the areas of a Cube, Triangle, and Rectangle individually in that order. From the main method, create a Shape object and call these area methods to demonstrate method overriding. Sample cutput is given below: Drawing a shape at (10,20) Drawing a rectangle at (30,40) with width 50 and height 60 Drawing a circle at {70,90} with radius 90 Drawing a rectangle at (100,110) with width 120 and height 130 Drawing a circle at {140,150) with radius 160 Cube area =150 Triangle area=3.5999999999999996 Rectangle area=12

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!