public class HelloWorld {
// java 我日你大爷
static int score1 = 86;
static int score2 = 92;
public static int sum() {
return score1+score2;
}
public static void main(String[] args) {
int allScore = sum();
System.out.println("总分:" + allScore);
}
}
// java 我日你大爷
static int score1 = 86;
static int score2 = 92;
public static int sum() {
return score1+score2;
}
public static void main(String[] args) {
int allScore = sum();
System.out.println("总分:" + allScore);
}
}
2017-09-01
已采纳回答 / 熬翔的熊喵
第一幅图的第九行代码出错,改为: this.score=score;原因: Rabbit类中的属性score的修饰符是private。被private修饰的属性,不能直接访问,需要通过方法来访问。你的第九行代码,写的是 score=score; 这样写,计算机会认为两个score都是方法参数里面的score。而this关键字,则代表了当前类的对象。所以在Rabbit类中,this.score则代表实例化一个Rabbit类,并调用它的属性score。 不足之处,还请谅解。
2017-09-01