public static void main(String[] args)
{
Shape3D my3DShape = new Shape3D(10, 20, 30);
Shape shapeHolder = my3DShape;
double area = shapeHolder.getArea();
// Veya
double area2 = ((Shape) my3DShape).getArea();
// Veya
Shape shape = new Shape3D(5, 10, 15);
double area3 = shape.getArea();
}
public class Shape3D extends Shape
{
private double width, height, depth;
public Shape3D(double width, double height, double depth)
{
super("3D SHAPE");
this.width = width;
this.height = height;
this.depth = depth;
}
public double getWidth()
{
return width;
}
public double getHeight()
{
return height;
}
public double getDepth()
{
return depth;
}
@Override
public double getArea()
{
return this.width * this.height * this.depth;
}
}
public abstract class Shape
{
protected String name;
public Shape(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public abstract double getArea();
}