Difference between Inheritance and Composition

前端 未结 17 1920
忘了有多久
忘了有多久 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:16

    Composition means creating an object to a class which has relation with that particular class. Suppose Student has relation with Accounts;

    An Inheritance is, this is the previous class with the extended feature. That means this new class is the Old class with some extended feature. Suppose Student is Student but All Students are Human. So there is a relationship with student and human. This is Inheritance.

提交回复
热议问题