abstract class figure
{
double d1,d2;
figure(double x,double y)
{
d1=x;
d2=y;
}
public abstract double area ();
}
class rectangle extends figure
{
rectangle(double a,double b)
{
super (a,b);
}
public double area ()
{
System.out.println("area of the rectangle is");
return d1*d2;
}
}
class triangle extends figure
{
triangle (double p,double q)
{
super(p,q);
}
public double area()
{
System.out.println("area of the triangle");
return(d1*d2)/2;
}
public static void main(String args[])
{
//figure f= new figure();
rectangle r= new rectangle(10,20);
triangle t= new triangle (15,20);
figure ff;
ff=r;
ff.area();
ff=t;
}
}
0 comments:
Post a Comment