public class HelloWorld {
static int score1 = 86;
static int score2 = 92;
public static int sum() {
int sum = score1 +score2;
return sum;
}
public static void main(String[] args) {
int allScore = HelloWorld.sum();
System.out.println("总分:" + allScore);
}
}
static int score1 = 86;
static int score2 = 92;
public static int sum() {
int sum = score1 +score2;
return sum;
}
public static void main(String[] args) {
int allScore = HelloWorld.sum();
System.out.println("总分:" + allScore);
}
}
2017-12-14
MInner a = new MInner();
// 调用内部类的方法
int newScore = a.getScore();
// 调用内部类的方法
int newScore = a.getScore();
2017-12-14
总而言之:静态变量和方法调用时,如果是在普通变量和方法中,需要通过创建对象的方法间接调用。如果是同为静态则可以直接调用(个人看法)
2017-12-13