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

 USING JAVA PLEASE. Question 1. Write a program that defines aShape class that demonstrates encapsulation by using private variables and public getters

USING JAVA PLEASE.

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 output is given below

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!