Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

In java which one is recommended to use i,e inheritance or composition ? give the reason.

user-image
Question added by Mohd shahnawaz khan , Associate Project , Cognizant Technology Solution
Date Posted: 2013/11/27
Mohd shahnawaz khan
by Mohd shahnawaz khan , Associate Project , Cognizant Technology Solution

We recommended to use composition , as using extends key word it inheriits all the method from the base class(parent class), which in certain cases increases the complexity and length of the code, while using composition we call only the specific method as the condition  demand.

 

Bassem Zohdy
by Bassem Zohdy , Senior Software Architect , HelpAG

the basic rule for that is:

inheritance = "is a" relationship

composition = "has a" relationship

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.