Question: Shape Hierarchy: - Create a base class called Shape with the following attributes and methods: - Attributes: ` color ` ( String ) and `

Shape Hierarchy:
- Create a base class called Shape with the following attributes and methods:
- Attributes: `color`(String) and `filled`(boolean).
- Methods:
-`getArea()`(abstract method)
-`getPerimeter()`(abstract method)
-`toString()` method that returns a string representation of the shape.
- Create two subclasses, `Circle` and `Rectangle`, that are inherited from the `Shape` class.
-`Circle` should have a `radius` attribute.
-`Rectangle` should have `width` and `length` attributes.
- Implement appropriate constructors and override the abstract methods in the subclasses.
2. Polymorphic Array:
- In the main class, create an array of `Shape` objects.
- Populate the array with instances of `Circle` and `Rectangle`.
- Display the details (color, filled, area, and perimeter) of each shape using polymorphism.
3. Interface:
- Define an interface called `Resizable` with a method `resize(double factor)` that represents resizing a shape.
- Make the `Rectangle` class implement the `Resizable` interface.
- In the main class, demonstrate polymorphism by resizing a `Rectangle` object using the `Resizable` interface.

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!