Search Interview Questions | ![]() ![]() Click here and help us by providing the answer. ![]() Click Correct / Improve and please let us know. |
|
| |||||||||||
Core Java - Interview Questions and Answers for 'Composition' - 7 question(s) found - Order By Newest | |||||||||||
![]() | |||||||||||
| |||||||||||
Ans. Composition - has-a relationship between objects. Inheritance - is-a relationship between classes. Composition - Composing object holds a reference to composed objects and hence relationship is loosely bound. Inheritance - Derived object carries the base class definition in itself and hence its tightly bound. Composition - Used in Dependency Injection Inheritance - Used in Runtime Polymorphism Composition - Single class objects can be composed within multiple classes. Inheritance - Single class can only inherit 1 Class. Composition - Its the relationship between objects. Inheritance - Its the relationship between classes. | |||||||||||
![]() ![]() | |||||||||||
![]() | |||||||||||
![]() ![]() ![]() ![]() ![]() ![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
| |||||||||||
Ans. Inheritance means a object inheriting reusable properties of the base class. Compositions means that an abject holds other objects. In Inheritance there is only one object in memory ( derived object ) whereas in Composition , parent object holds references of all composed objects. From Design perspective - Inheritance is "is a" relationship among objects whereas Composition is "has a" relationship among objects. | |||||||||||
![]() | |||||||||||
![]() ![]() ![]() ![]() ![]() ![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
| |||||||||||
Ans. Inheritance. | |||||||||||
![]() | |||||||||||
![]() ![]() ![]() ![]() ![]() ![]() | |||||||||||
Ans. Yes. | |||||||||||
![]() | |||||||||||
![]() ![]() ![]() | |||||||||||
![]() | |||||||||||
| |||||||||||
Ans. Yes, to a certain extent. But the objective for Final class could be beyond just enforcing composition as certain classes might have been created without inheritance or composition in mind. | |||||||||||
![]() | |||||||||||
![]() ![]() ![]() ![]() | |||||||||||
| |||||||||||
Ans. Composition and Inheritance are the different types of Associations for Classes. Composition is a has-a association between classes. Inheritance is a is-a association between classes. | |||||||||||
![]() | |||||||||||
![]() ![]() ![]() | |||||||||||
| |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() ![]() ![]() ![]() ![]() ![]() | |||||||||||
| |||||||||||
| |||||||||||
| |||||||||||