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 |
What is sortedset in java?
What is inheritance?
5 Answers Accenture, Hexaware, Syntel,
What is a function argument in java?
What is currentthread()?
What is a map? What are the implementations of map?
Why is java architectural neutral?
Why do we need wrapper classes?
Why java does not supports multiple inheritance?
Can we override the overloaded method?
who was the founder of java
32 Answers CTS, HCL, ProKarma,
What is io stream in java?
What are the 6 mandatory procedures for iso 9001?