The document defines an abstract Area class with an abstract computearea() method. It then defines three subclasses (Square, Circle, Rectangle) that extend Area and implement computearea() to calculate the area of each shape. The main method creates instances of each subclass and calls computearea() to output the area.
The document defines an abstract Area class with an abstract computearea() method. It then defines three subclasses (Square, Circle, Rectangle) that extend Area and implement computearea() to calculate the area of each shape. The main method creates instances of each subclass and calls computearea() to output the area.
Create another 3 classes for computing Area of Square, Rectangle and Circle, and all of them will extend Area class. Use concept of Inheritance.
SOL:
//abstract class definition
abstract class Area { double a; double area; abstract void computearea(); }
class Square extends Area
{ void computearea() { a=5.5; //You can enter any value, or take input from user area=a*a; System.out.println("Area of Square is "+area+"sq units"); } }
class Circle extends Area
{ void computearea() { a=2.5; area=3.14*a*a; System.out.println("Area of Circle is "+area+"sq units"); } }
class Rectangle extends Area
{ double b; //for breadth void computearea() { a=4.0; b=2.0; area=a*b; System.out.println("Area of Rectangle is "+area+"sq units"); } }
public class Main
{ public static void main() { Square s=new Square(); s.computearea(); Circle c=new Circle(); c.computearea(); Rectangle r=new Rectangle(); r.computearea(); }