abstract
class figure
{float
l,b;
figure(float x,float y)
{l=x;
b=y; }
abstract float area();
}
class
rectangle extends figure
{
rectangle(float a,float b)
{
super(a,b); }
float
area()
{
return(l*b); }
}
class
triangle extends figure
{triangle(float
a,float b)
{
super(a,b); }
float area()
{return(l*b/2); }
}
class
figurearea
{
public static void main(String a[])
{
rectangle r=new rectangle(2.5f,2.5f);
triangle t=new triangle(1f,2.0f);
figure f=r;
System.out.println("area of
rectangle="+f.area());
f=t;
System.out.println("area of
triangle="+f.area()); }
}
Output
|
This blog is mainly developed for individuals,who were interested in programming using C,C++,java and SQL.
No comments:
Post a Comment