super

来源:互联网 发布:如何关闭淘宝网店 编辑:程序博客网 时间:2024/03/29 09:47

java中把父类叫做超类基类

在子类中,若想调用父类的成员,用super. 来调用

调用自己的成员 this.



构造方法:

子类构造方法的第一行,有一个隐式代码super();

super() 调用父类的构造方法

super(参数)调用父类有参数的构造方法


eg:

public class Person{

    public Person(String name, int age){}

   public Person(){}    //建议写上空参

}



public student extends Person{

    public student(String name,int age){

          super(name,age)   / /super必须卸载第一行

}

}

不能同时存在super和this() 因为两个都必须在第一行