Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Q. Create an abstract class 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();
}

You might also like