interface Area
{
public abstract double getArea();
}
class Zheng implements Area
{
private int chang, kuan;
Zheng(int chang,int kuan)
{
this.chang = chang;
this.kuan = kuan;
}
//如果子类继承父类它的可见性不能降低(即你定义的接口中的 getArea()方法为public ,所以子类 Zheng的getArea()必须为public才正确
public double getArea()
{
return chang*kuan;
}
}
class AreaDemo
{
public static void main(String[] args)
{
Zheng z = new Zheng(3,5);
double area = z.getArea();
System.out.println("area = "+area);
}
}
//如果你要检测其修饰符你自己在我发的代码基础上 子类 Zheng 里面的double getArea()前面该修饰符就是 |