Start with the idea
A trait may provide a method body that implementations inherit. Defaults reduce repetition, while required methods still define the minimum contract each type must supply.
A default method supplies behavior that implementers may inherit. In Summary, each type must provide title(), while summary() can be built from that required method. A new type gets a useful summary immediately after implementing the minimal contract. It may override the default when its presentation needs more context, but callers can still rely on the trait method existing.
This is a way to centralize a policy that is genuinely shared.
Keep learning, for free
The rest of this lesson is waiting for you.
Create a free account to read the complete explanation, see the infographic, explore the code, and try the exercises. All 742 lessons and algorithm steps are included.
No payment details. Your account opens the complete Academy.