What are the difference between composition and inheritance in java?



What are the difference between composition and inheritance in java?..

Answer / Yogendra Pandey

Composition and inheritance are both ways to create relationships between classes in Java, but they differ in their implications. Composition creates a 'has-a' relationship, where an object contains other objects as its parts. Inheritance creates an 'is-a' relationship, where a subclass inherits properties and methods from its superclass. Composition provides more flexibility, as the contained objects can be changed at runtime, while inheritance creates a rigid hierarchical structure.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

What is sortedset in java?

1 Answers  


What is inheritance?

5 Answers   Accenture, Hexaware, Syntel,


What is a function argument in java?

1 Answers  


What is currentthread()?

1 Answers  


What is a map? What are the implementations of map?

1 Answers  


Why is java architectural neutral?

1 Answers  


Why do we need wrapper classes?

1 Answers  


Why java does not supports multiple inheritance?

3 Answers   TCS, VSoft,


Can we override the overloaded method?

1 Answers  


who was the founder of java

32 Answers   CTS, HCL, ProKarma,


What is io stream in java?

1 Answers  


What are the 6 mandatory procedures for iso 9001?

1 Answers  


Categories