继承与构成的差异成分和继承是一样的吗?如果我想实现组合模式,我如何在Java中做到这一点?
3 回答
德玛西亚99
TA贡献1770条经验 获得超3个赞
HAS A
IS A
Example
class Engine {} // The Engine class.class Automobile {} // Automobile class which is parent to Car class.class Car extends Automobile { // Car is an Automobile, so Car class extends Automobile class. private Engine engine; // Car has an Engine so, Car class has an instance of Engine class as its member.}
添加回答
举报
0/150
提交
取消