Owen R. Largo Bit - CT 2B Day 03/05/2021
Owen R. Largo Bit - CT 2B Day 03/05/2021
1. The Composition is more flexible because you can change the implementation at runtime by
calling setXXX() method, but Inheritance cannot be changed i.e. you cannot ask a class to
implement another class at runtime.
2. Composition builds HAS-A relationship while Inheritance builds IS-A relationship e.g. A Room
HAS A Fan, but Mango IS-A Fruit.
3. The parent-child relationship is best represented using Inheritance but If you just want to use
the services of another class use Composition.
OWEN R. LARGO BIT – CT 2B DAY 03/05/2021
call that method from subclass then the one in the subclass will be invoked but if you call the
same method from superclass then the one in superclass will be invoked. This is known as
method hiding in Java.