• super关键字
    • 一个引用变量,用于引用父类对象
    • 父类和子类都具有相同的命名方法,要调用父类方法时使用
    • 父类和子类都具有相同的命名属性,要调用父类中的属性时使用
    • super也是父类的构造函数,格式super(函数);
      • 注意点 调用super()必须是类构造函数中的第一条语句,否则编译不通过

  • 注意
    • 每个子类构造方法的第一个语句,都是隐含地调用super(),如果父类没有这种形式的构造函数,那么在编译的时候就会报错

public class Father { 
    public Father(){ 
    System.out.println("father ⽆参构造函数"); 
    }
   } 
public class Children extends Father{ 
public Children(){ 
//默认存在,写和不写都⾏ super(); 
System.out.println("Child⽆参构造函数");}
 }   

  

  • this()和super()都指的是对象,均不可以static环境中使用
    • 包括:static变量,static方法,static语句块

相关文章:

  • 2021-06-28
  • 2022-01-03
  • 2021-06-30
  • 2022-12-23
  • 2022-12-23
  • 2021-11-13
  • 2021-05-31
  • 2021-07-02
猜你喜欢
  • 2022-01-22
  • 2021-05-20
  • 2021-06-18
  • 2021-11-14
  • 2021-10-19
  • 2021-11-10
  • 2021-11-22
相关资源
相似解决方案