使用在子类的构造器中使用super()可以调用父类的构造器[code]public class Person {
public String name;
public Person(String name) {
this.name = name;
System.out.println("这时父类的构造器");
}
}
public class Student extends Person{
public Student(String name) {
super(name);
System.out.println("这是子类的构造器");
}
public static void main(String[] args) {
Student s = new Student("zhagnsan");
}
}[/code] |