tij一个关于继承的问题

asiaec 2002-02-02 03:56:09
//: c06:PlaceSetting.java
// Combining composition & inheritance.

class Plate {
Plate(int i) {
System.out.println("Plate constructor");
}
}

class DinnerPlate extends Plate {
DinnerPlate(int i) {
super(i);
System.out.println(
"DinnerPlate constructor");
}
}

class Utensil {
Utensil(int i) {
System.out.println("Utensil constructor");
}
}

class Spoon extends Utensil {
Spoon(int i) {
super(i);
System.out.println("Spoon constructor");
}
}

class Fork extends Utensil {
Fork(int i) {
super(i);
System.out.println("Fork constructor");
}
}

class Knife extends Utensil {
Knife(int i) {
super(i);
System.out.println("Knife constructor");
}
}

// A cultural way of doing something:
class Custom {
Custom(int i) {
System.out.println("Custom constructor");
}
}

public class PlaceSetting extends Custom {
Spoon sp;
Fork frk;
Knife kn;
DinnerPlate pl;
PlaceSetting(int i) {
super(i + 1);
sp = new Spoon(i + 2);
frk = new Fork(i + 3);
kn = new Knife(i + 4);
pl = new DinnerPlate(i + 5);
System.out.println(
"PlaceSetting constructor");
}
public static void main(String[] args) {
PlaceSetting x = new PlaceSetting(9);
}
} ///:~

为什么运行了之后首先显示的不是第一个类的构造函数呢
...全文
58 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
asiaec 2002-02-03
  • 打赏
  • 举报
回复
。。。。
asiaec 2002-02-02
  • 打赏
  • 举报
回复
为什么没有人里我 是觉得太简单了吗

23,407

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧