天天看點

java代碼塊 學習

class Student {
            static {
                System.out.println("Student 靜态代碼塊");
            }

            {
                System.out.println("Student 構造代碼塊");
            }

            public Student() {
                System.out.println("Student 構造方法");
            }
        }

        class Demo2_Student {
            static {
                System.out.println("Demo2_Student靜态代碼塊");
            }

            public static void main(String[] args) {
                System.out.println("我是main方法");

                Student s1 = new Student();
                Student s2 = new Student();
            }
        }