static 关键字详解
package OOP.Demo07;
import sun.util.resources.sq.CalendarData_sq;
public class Student {
private static int age;
private double score;
public void run(){
System.out.println("跑");
}
public static void go(){
System.out.println("出发");
}
public static void main(String[] args) {
Student s1 = new Student();
System.out.println(Student.age);
System.out.println(s1.score);
go();
Student.go();
s1.run();
}
}
package OOP.Demo07;
public class Person {
{
System.out.println("匿名代码块!");
}
static {
System.out.println("静态代码块!");
}
public Person() {
System.out.println("构造方法!");
}
public static void main(String[] args) {
Person person = new Person();
System.out.println("--------------");
Person person1 = new Person();
}
}
package OOP.Demo07;
import static java.lang.Math.random;
public class Text {
public static void main(String[] args) {
System.out.println(random());
}
}