转载请注明出处:http://blog.csdn.net/u011569040/article/details/42837001
1.生成子类的过程
2.使用super 调用父类构造函数的方法
看程序里面的备注
class Person {
String name;
int age;
Person(){
System.out.println("我是无参构造函数");
}
Person(String name,int age){
this.name = name ;
this.age = age;
System.out.println("Person的有参构造函数");
}
}
class Student extends Person{
int grade;
//super(); 在子类的构造函数中必须调用父类的构造函数,否则系统自动添加super(),super(参数)可以调用父类有参构造函数
System.out.println("Student的无参构造函数");
}
Student(int grade){
this();//this和super很像,都需写在第一行,都是调用构造函数,但this()是调用自己的无参构造函数,而super()是调用父类的无参构造函数
}
}