public class HelloWorld {
static int score1 = 86;
int score2 = 92;
public static int sum() {
HelloWorld hw = new HelloWorld();
return hw.score2 + score1;
}
public static void main(String[] args) {
int allScore = sum();
System.out.println("总分:" + allScore);
}
}
static int score1 = 86;
int score2 = 92;
public static int sum() {
HelloWorld hw = new HelloWorld();
return hw.score2 + score1;
}
public static void main(String[] args) {
int allScore = sum();
System.out.println("总分:" + allScore);
}
}
2017-09-21
public class HelloWorld {
// 定义静态变量,保存班级名称
static String className = "JAVA开发一班";
public static void main(String[] args) {
// 访问静态变量,输出班级名称
System.out.println( HelloWorld.className );
}
}
// 定义静态变量,保存班级名称
static String className = "JAVA开发一班";
public static void main(String[] args) {
// 访问静态变量,输出班级名称
System.out.println( HelloWorld.className );
}
}
2017-09-21
最赞回答 / Antique
咦,自己查资料发现原因如下:首先接口由于少了方法的实现,所以不能实例化,这个与抽象类一致,由于不能实例化,所以对于成员变量只能是static由于是static所以所有实现了接口的类共享一份由于所有人共享一份,同时接口的定义是“所有实现该接口的人都共同拥有这些属性/功能”由于所有的实现类都共同拥有,若是变量则实现类A的改变会导致实现B的改变会由于实现类的操作而改变的东西违反了接口的定义所以为了确保每个实现的接口都共同遵守这个“属性”,属性必须是final由于接口本身的定义是public最后就是 public...
2017-09-21
System.out.println("输入的数据有误");
newScreen = 5f;//默认值应该赋给newScreen,而不是screen
newScreen = 5f;//默认值应该赋给newScreen,而不是screen
2017-09-20
static int score1 = 86;
int score2 = 92;
public static int sum() {
HelloWorld qwe = new HelloWorld();
int qwer=score1+qwe.score2;
return qwer;
}
public static void main(String[] args) {
int allScore=sum();
System.out.println("总分:" + allScore);
int score2 = 92;
public static int sum() {
HelloWorld qwe = new HelloWorld();
int qwer=score1+qwe.score2;
return qwer;
}
public static void main(String[] args) {
int allScore=sum();
System.out.println("总分:" + allScore);
2017-09-20