Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Mastering Java: The Ultimate Quiz for 'Thinking in Java'. Dive deep into Java with multiple-choice questions. Challenge yourself with quiz questions designed to test and improve your understanding of the 'Thinking in Java' book. Get ready for your exam!

Practice this question and more.


Why does Fill2 not require a Collection as Fill did?

  1. Because it uses raw types instead of generic types

  2. It uses reflection to dynamically call methods

  3. It only requires an implementer of an Addable interface

  4. Java 8 introduced default methods in interfaces

The correct answer is: It only requires an implementer of an Addable interface

Unlike the original Fill method, Fill2 only requires an implementer of the Addable interface because it was specifically designed to work with custom objects that implement this interface. Option A is incorrect because raw types are not used in Fill2; it uses generics as well, just in a different way. Option B is incorrect because Fill2 does not use reflection, it instead relies on the methods defined in the Addable interface. Option D is incorrect because the use of default methods in interfaces is not related to the reason why Fill2 does not require a Collection.