【发布时间】:2015-03-04 22:13:07
【问题描述】:
我在寻找考试准备问题时遇到了这段代码。 我不明白什么在调用超类构造函数 在这段代码中?
输出是 ---> feline cougar cc
THL
public class Feline{
public String type = "f ";
public Feline(){
System.out.print("feline ");
}
}
-
public class Cougar extends Feline {
public Cougar(){
System.out.print("cougar ");
}
public static void main(String[] args){
new Cougar().go();
}
void go(){
type = "c ";
System.out.print(this.type + super.type);
}
}
【问题讨论】:
-
在执行子类的构造函数体之前隐式完成。
-
添加覆盖以抑制超级调用。
标签: java inheritance constructor superclass super