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