使用组合为什么还会出现继承现象?
public class Problem {
public static void main(String[] args){
Bird2 b = new Bird2();
}
public Problem(){
//super(); //构造器中super()必须是第一句
System.out.print("构建一个动物" + "\n");
}
}
class Bird2 {
Problem p = new Problem();
public Bird2() {
//super();
System.out.println("建一个鸟对象");
}
}
运行结果:
构建一个动物
建一个鸟对象
这里明明没有用到继承的方法,Bird2 b = new Bird2();语句不是调用Bird2中的构造器吗?为什么会打印“构建一个动物”这句?求大神解答,谢谢!