(JAVA Programming) Demonstrate the Object Oriented Programming concepts (Inheritance, Polymorphism, and Encapsulation). create a class called Shape. which has a color field and methods for getting and setting the color for each shape, as well as a method for calculating the area of the shape. The Circle, Square, and Rectangle classes are the shapes to include where they inherit from Shape and implement their own versions of the getArea() and display() methods. The Main class creates instances of all three classes and calls their display() methods, demonstrating polymorphism. The color field in the Shape class is encapsulated, and it is accessed through getter and setter methods. Here is a sample output for this project: Shape: Circle Color: Red Radius: 5.0 Area: 78.53981633974483 ++++++++++++++++++++ Shape: Rectangle Color: Blue Width: 3.0 Height: 4.0 Area: 12.0 ++++++++++++++++++++ Shape: Square Color: Yellow Width: 4.0 Area: 16.0
(JAVA
Demonstrate the Object Oriented Programming concepts (Inheritance, Polymorphism, and Encapsulation).
create a class called Shape. which has a color field and methods for getting and setting the color for each shape, as well as a method for calculating the area of the shape. The Circle, Square, and Rectangle classes are the shapes to include where they inherit from Shape and implement their own versions of the getArea() and display() methods. The Main class creates instances of all three classes and calls their display() methods, demonstrating polymorphism. The color field in the Shape class is encapsulated, and it is accessed through getter and setter methods.
Here is a sample output for this project:
Shape: Circle
Color: Red
Radius: 5.0
Area: 78.53981633974483
++++++++++++++++++++
Shape: Rectangle
Color: Blue
Width: 3.0
Height: 4.0
Area: 12.0
++++++++++++++++++++
Shape: Square
Color: Yellow
Width: 4.0
Area: 16.0
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 6 images