其实只要记住只有静态方法在调用非静态方法/变量的时候需要用类方法或者对象来调用就可以,其他情况都可以直接调用各类方法或者变量。
2016-11-10
这个和第一章方法那一节是不是重复了?这个比较基础是不是应该放到方法那一节之前呢?我是学过C,所以对于方法调用学得比较快,类似于C语言的函数调用。对于没学过的同学,我觉得可能会困惑于方法那一节,建议这一章加到第一季方法那一节前面。
2016-11-10
public class HelloWorld{
// 定义静态变量,保存班级名称
String className = "JAVA开发一班";
static HelloWorldhello = new HelloWorld();
public static void main(String[] args) {
// 访问静态变量,输出班级名称
System.out.println( hello.className );
}
}
// 定义静态变量,保存班级名称
String className = "JAVA开发一班";
static HelloWorldhello = new HelloWorld();
public static void main(String[] args) {
// 访问静态变量,输出班级名称
System.out.println( hello.className );
}
}
2016-11-09
public class Static{
static int score1 = 86;
static int score2 = 92;
public static int sum() {
return score1+score2;
}
public static void main(String[] args) {
Static allScore = new Static();
System.out.println(allScore.sum());
}
}
static int score1 = 86;
static int score2 = 92;
public static int sum() {
return score1+score2;
}
public static void main(String[] args) {
Static allScore = new Static();
System.out.println(allScore.sum());
}
}
2016-11-09