Difference between Inheritance and Composition

前端 未结 17 2013
忘了有多久
忘了有多久 2020-11-22 02:35

Are Composition and Inheritance the same? If I want to implement the composition pattern, how can I do that in Java?

17条回答
  •  礼貌的吻别
    2020-11-22 03:09

    Inheritance between two classes, where one class extends another class establishes "IS A" relationship.

    Composition on the other end contains an instance of another class in your class establishes "Has A" relationship. Composition in java is is useful since it technically facilitates multiple inheritance.

提交回复
热议问题