Grokking Java Interview Questions
Vote

0% completed

​

Composition vs Inheritance

A set receives 3 products in one addAll() call, and its counter reports 6. The set itself is correct and holds 3 elements. The counter belongs to a subclass of HashSet with two short overrides, and each of them looks right when it is read alone.

The number 6 is the result of a parent class that calls its own methods. The questions below compare the two ways to reuse a class, trace where the 6 comes from, state the rule that every subclass must satisfy, and show how to add behavior without a subclass.

What is the difference between inheritance and composition?

Level: Junior

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content