static

package base.Demo05;
import static java.lang.Math.random;//静态导入包

public class Person {

    {
     //代码块(匿名代码块)
        System.out.println("匿名代码块");
    }
    static {
        //静态代码块
        System.out.println("静态代码块");
    }

    public Person() {
        System.out.println("构造方法");
    }

    public static void main(String[] args) {
        Person s1 = new Person();
        System.out.println(
                "========"
        );
        Person s2 = new Person();
        System.out.println(random());
    }
}
//代码刚开始创建会先走静态代码块,而且只会调用一次,后面使用匿名代码块,再到构造方法
package base.Demo05;

public class Student {

    private static int age;//静态变量
    private double score;//非静态变量

    public void run(){

    }

    public static void  go(){

    }

    public static void main(String[] args) {
        Student s1 = new Student();
        System.out.println(Student.age);
        System.out.println(s1.score);
        System.out.println(s1.age);

        Student.go();
        s1.run();
    }
}