-
Program:-
abstract
class shape
{
double x,y;
void get(double h,double w)
{
x=h;
y=w;
}
abstract void area();
}
class
rectangle extends shape
{
void area()
{
System.out.println("Area
of rectanle is: "+(x*y));
}
}
class
triangle extends shape
{
void area()
{
System.out.println("Area
of Triangle is: "+(0.5*x*y));
}
}
class u43
{
public static void main(String
args[])
{
shape s;
s=new rectangle();
s.get(5.0,6.0);
s.area();
s=new triangle();
s.get(5.0,6.0);
s.area();
}
}
No comments:
Post a Comment