//abstractdemo.java
abstract class Shape
{
int x,y;
void getdata(int x1,int y1)
{
x=x1;
y=y1;
}
abstract void area();
}
class Rectangle extends Shape
{
void area()
{
int a=x*y;
System.out.println("Area of Rectangle having width"+x+"and Height="+y+"is"+a);
}
}
class Triangle extends Shape
{
void area()
{
int a=(x*y)/2;
System.out.println("Area of Triangle="+a);
}
}
class AbstractDemo
{
public static void main(String arg[])
{
Rectangle r=new Rectangle();
r.getdata(20,10);
r.area();
Triangle t=new Triangle();
t.getdata(30,40);
t.area();
}
}
No comments:
Post a Comment