我正在使用接口实现此程序以实现层次继承。它显示了这个错误:
"Error:(26, 11) java: compute(float,float) in com.xx.Rectangle cannot
implement compute(float,float) in com.xx.Area attempting to assign weaker
access privileges; was public"
请帮忙。 该计划:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Rectangle rect=new Rectangle();
Circle cir=new Circle();
Area area;
area=rect;
Scanner s = new Scanner(System.in);
int a=s.nextInt();
int b = s.nextInt();
System.out.println("Area of Rectangle = "+area.compute(a,b));
area=cir;
System.out.println("Area of Circle = "+area.compute(a,b));
}
}
interface Area{
final static float pi=3.14f;
float compute(float x,float y);
}
class Rectangle implements Area{
float compute(float x,float y){
return(x*y);
}
}
class Circle implements Area{
float compute(float x,float y){
return(pi*x*y);
}
}