java中的继承(IS-A)与组合(HAS-A)关系
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24168116/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Inheritance (IS-A) vs. Composition (HAS-A) Relationship in java
提问by faisal khan
Inheritance (IS-A) vs. Composition (HAS-A) Relationship
继承 (IS-A) 与组合 (HAS-A) 关系
please someone explaine what is Inheritance (IS-A & HAS)relationship in java
请有人解释java中的继承(IS-A和HAS)关系是什么
回答by user2810895
Inheritance: Dog
'is an' Animal
. In Java this is done by the extends
keyword.
继承:Dog
'是一个' Animal
。在 Java 中,这是通过extends
关键字完成的。
Composition: Dog
'has' Eyes
. In Java this is done by having Dog an instance object of Eye.
组成:Dog
'有' Eyes
。在 Java 中,这是通过让 Dog 成为 Eye 的实例对象来完成的。