Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

ipsec is designed to provide secury at the

Answered: 1 week ago

Question

Is SHRD compatible with individual career aspirations

Answered: 1 week ago