super 在继承中有三个功能:
Super() 表示子类指定调用基类的构造函数版本 ,必须放在构造函数第一行
Super. 在子类中访问父类中继承的数据(子类 data / 父类super.data)
Super.func() 访问基类的成员方法
package s1;
class person {
String name="zhangsan";
int age;
public person() {
print();
this.age=0;
this.name=name;
}
public void print() {
System.out.println("名字" + name + "年龄 " +age);
}
}
public class student extends person {
public student() {
super(); // 调用基类的构造函数
}
public static void main(String[] args) {
new student();
}
}