hello guys, what is the advantage of inheriting a parent class A compared to creating a new object of class A if we want to use class A's method? Is it because of method overriding?
I'm not available, my BF's name is WORK.
posted 10 years ago
You can achieve code reuse in two ways:
1. implementation-inheritance (Gives you polymorphism as well) 2. composition (Can get polymorphism by using interface-inheritance)
Inheritance allows you to have a default behaviour in your parent class and subclasses can override this default behaviour. Implementation-Inheritance strongly couple classes together. So should favour interface inheritance with composition for reuse over implementation inheritance.