This Java project demonstrates the concept of abstract classes and method overriding using geometric shapes like Circle and Rectangle. The program uses abstraction to define a common interface (Shape
) and allows subclasses to provide specific implementations for calculating the area and perimeter.
AbstractEx.java
-
Abstract class
Shape
with two abstract methods:double perimeter()
double area()
-
Concrete classes:
Circle
: Implements perimeter and area using radius.Rectangle
: Implements perimeter and area using length and breadth.
-
Demonstrates:
- Abstraction
- Inheritance
- Method Overriding
- Polymorphism (by assigning
Circle
to aShape
reference)
The Perimeter of Circle: 65.97344572538566 The Area of Circle: 346.3605900582747 Accessing Circle Area using Shape reference: 346.3605900582747 The Perimeter of Rectangle: 60.0 The Area of Rectangle: 200.0