Poly java main method Declareinit a new object of type Trian
Solution
public abstract class Shape
{
private double height;
private double width;
public void setSize(double height, double width)
{
this.height=height;
this.width=width;
}
public double getHeight()
{
return height;
}
public double getWidth()
{
return width;
}
public abstract double setArea();
}
public class Rectangle extends Shape
{
public double getArea()
{
return getHeight() * getWidth();
}
}
public class Triangle extends Shape
{
public double getArea()
{
return (getHeight() * getWidth()) / 2;
}
}
Public class AbstractTest
{
public static void main (String[] args)
{
Shape shape;
Rectangle rect=new Rectangle();
shape = rect;
shape.setSize(81,4);
System.out.println(Ärea of rectangle : \"+ shape.getArea());
Triangle tri=new Triangle ();
shape=tri;
shape.setSize(47,6);
System.out.println(\"Area of triangle : \" + shape.getArea());
}
}

