following is the program i wanted to print the output of areas of both triangle and rectangle, but im not getting it.....please help me in getting the areas of both...thank you
class Shape
{
int dim1;
int dim2;
Shape(int a,int B)
{
dim1=a;
dim2=b;
}
void rotate()
{
System.out.println("rotating");
}
void erase()
{
System.out.println("erasing");
}
}
class Rectangle extends Shape
{
Rectangle(int l,int B)
{
super(l, B);
}
int getArea()
{
return dim1*dim2;
}
}
class Triangle extends Shape
{
Triangle(int b,int h)
{
super(b,h);
}
int getArea()
{
return(dim1*dim2)/2;
}
}
class Run1
{
public static void main(String[] args)
{
Rectangle rect=new Rectangle(10,20);
rect.getArea();
rect.rotate();
rect.erase();
System.out.println("-----------------");
Triangle t1=new Triangle(20,40);
t1.getArea();
t1.rotate();
t1.erase();
}
}