26 super关键字

super 的使用:

public Cat(String name, int month){
/**
* 子类的构造的过程中必须调用其父类的构造方法
* 子类构造默认调用父类无参构造方法
* 可以通过super()调用父类允许被访问的其他构造方法
* super()必须放在子类构造方法中,且必须放在有效代码的第一行.
* super()不能在静态方法中使用
* 构造方法调用时,super和this不能同时出现
*/
super(name,month);
System.out.println("我是子类的带参构造方法");
}

猜你喜欢

转载自www.cnblogs.com/CPU-Easy/p/12168533.html