学习JAVA,能进来帮一下么?

来源:百度知道 编辑:UC知道 时间:2024/06/14 05:59:43
interface Fruits {
double price = 30;
double num = 50;

double getTotal();

double getAdd();
}

class Apple implements Fruits {
private String color;
private int num;
private int price;

Apple(String color, int num, int price) {
this.color = color;
this.num = num;
this.price = price;
}

double getTotal() {//这里也出错说Cannot reduce the visibility of the inherited method from Fruits
return this.num * this.price;
}

double getAdd() { //这里会出错,说是Cannot reduce the visibility of the inherited method from Fruits
return this.num + this.price;
}
}

错误的意思是要你写成,和类型没有任何关系:

public double getTotal()
public double getAdd()

private int num;
private int price;
你这里的num和price定义成int 了,这样会和接口的double混淆的,改成double吧

恩,这回楼上的说对了,没有错误了,路过,学习啦!呵呵!

数据类型好乱,呵呵,跟我开始一样,加油学习吧。。。