January 2020
Intermediate to advanced
532 pages
13h 31m
English
Another problem with implementation inheritance is that changes to the base class (parent class) can possibly break functionalities of its subclasses. From the earlier Java example, we have a CountingBag class that extends from the Bag class. Let's look at the complete source code, including the main function:

The program simply creates a CountingBag object. Then it adds apple using the add method and adds banana and orange using the addMany method. Finally, it prints out the items in the bag and the size of the bag. The output is shown in the following code:
Everything looks fine at the moment. But let's say ...
Read now
Unlock full access