且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

java中的继承(IS-A)与组合(HAS-A)的关系

更新时间:2023-09-25 07:51:03

继承'是'动物。在Java中,这是通过 extends 关键字完成的。

Inheritance: Dog 'is an' Animal. In Java this is done by the extends keyword.

作文'有'眼睛。在Java中,这是通过让Dog成为Eye的实例对象来完成的。

Composition: Dog 'has' Eyes. In Java this is done by having Dog an instance object of Eye.