Experiment No.
NAME: RAVIRAJ SATISH KHARADE ROLL NO- 74
5. Write a java program to create an abstract class named Shape that contains two integers and an
empty method named print Area (). Provide three classes named Rectangle, Triangle and Circle
such that each one of the classes extends the class Shape. Each one of the classes contains only
the method print Area () that prints the area of the given shape ( ABSTRACT CLASS)
abstract class Shape
{
int d1;
int d2;
abstract void printArea();
}
class Rectangle extends Shape
{
@Override
void printArea() {
float length=2.5f;
float breadth=1.2f;
System.out.println("Area of Rectangle is "+(length*breadth));
}
class Triangle extends Shape
{
@Override
void printArea() {
float base=5.0f;
float height=3.4f;
System.out.println("Area of Traingle is "+(1/2*(base*height)));
}
class Circle extends Shape
{
@Override
void printArea() {
float pi=3.14f;
int r=2;
System.out.println("Area of Circle is "+(pi*(r*r)));
}
public class PS2UnitIII {
public static void main(String[] args) {
Rectangle r=new Rectangle();
Circle c=new Circle();
Triangle t=new Triangle();
r.printArea();
c.printArea();
t.printArea();
}
}