·构造块 public class test { public static void main(String arg[]) { Student a = new Student("1111 1111" , "a"); Student b = new Student("2222 2222" , "b"); Student c = new Student("3333 3333" , "c"); } } class Student { private String ID; private String name; static String school = "陕西师范小学"; //用static修饰的属性相当于全局变量,牵一发而动全身 Student(String ID , String name) { this.ID = ID; this.name = name; System.out.println("学生完成登记"); } { System.out.println("来了一个新的学生"); } //构造块,会优先于构造函数执行 public void get_info() { System.out.println("ID : " + this.ID + "name : " + this.name + "school : " + this.school); } }