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

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Spatial Databases A Tour

Authors: Shashi Shekhar, Sanjay Chawla

1st Edition

0130174807, 978-0130174802

More Books

Students also viewed these Databases questions

Question

1 Defi ne and evaluate your service strategy.

Answered: 1 week ago