top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Java: What is the benefit of Composition over Inheritance?

+2 votes
338 views
Java: What is the benefit of Composition over Inheritance?
posted Jul 28, 2015 by Karthick.c

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

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.

answer Oct 24, 2016 by Farhan
...