+1 vote
in JAVA by
The difference between Inheritance and Composition?

2 Answers

0 votes
by
Though both allows code reuse, Composition is more flexible than Inheritance because it allows you to switch to another implementation at run-time. Code written using Composition is also easier to test than code involving inheritance hierarchies.
0 votes
by

Inheritance and composition are two different ways to achieve code reuse in Java. Inheritance provides a way to create a new class based on an existing class, while composition provides a way to reuse code by composing objects of different classes into a single object.

...