package work;
//定义一个Shape接口,接口中含有一个抽象方法,此抽象方法接收一个double类型的参数
interface Shape
{
double area(double x);
}
//定义一个Square类,实现Shape接口
class Square implements Shape
{
double area(double x)
{
double a=x*x;
return a;
System.out.println("正方形的面积为 "+a);
}
}
//定义一个Circle类,实现Shape接口
class Circle implements Shape
{
double area(double x)
{
double a=3.14*x*x;
return a;
System.out.println("圆的面积为 "+a);
}
}
public class Test02 {
public static void main(String[] args)
{
// TODO Auto-generated method stub
Square square=new Square();
square.area(2.00);
Circle circle=new Circle();
circle.area(3.00);
}
}
运行报错提示:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Cannot reduce the visibility of the inherited method from Shape
at work.Square.area(Test02.java:12)
at work.Test02.main(Test02.java:37)