Inheritance (IS-A) vs. Composition (HAS-A) Relationship,Java Sample

Inheritance (IS-A) vs. Composition (HAS-A) Relationship

 

One of the advantages of Object-Oriented programming language is code reuse. There are two ways we can do code reuse either by implementation of inheritance (IS-A relationship), or object composition (HAS-A relationship). Although the compiler and Java virtual machine (JVM) will do a lot of work for you when you use inheritance, you can also get at the functionality of inheritance when you use composition.

inheritence vs compositions

Leave a comment