🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Composition vs Inheritance: all 10 questions

Quiz: Composition vs Inheritance · Question 3 of 10

In the composition version, why is there no double counting?

In the composition version, why is there no double counting?

  1. A.inner.addAll() calls inner's own add, which our class did not override
  2. B.Composition makes methods run only once
  3. C.Java removes duplicate calls automatically
  4. D.Because addAll was deleted
Answer & explanation

Correct answer: inner.addAll() calls inner's own add, which our class did not override

Our class wraps the set; the set's internal calls never come back to our methods.

Can you get the rest right without peeking?

Take the timed Quiz: Composition vs Inheritance quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →