java接口相关习题
interface Graphics
{ //接口里面只能用抽象方法
public abstract double area();
}
//设置 平面类
class PlaneGraphics1
{
private String shape; //形状
//构造方法,有参数
public PlaneGraphics1(String shape)
{
this.shape=shape;
}
//无参数
public PlaneGraphics1()
{
this("未知图形1");
}
//打印
public void print()
{
}
}
//长方形 ,继承接口必要实现接口的抽象方法,不然会报错的。
class Rectangle extends PlaneGraphics1 implements Graphics
{
protected double length;
protected double width;
//构造方法
public Rectangle(double length,double width)
{
this.length=length;
this.width=width;
}
//正方形构造方法
public Rectangle(double w