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 use interfaces instead of concrete base classes?

  1. To allow multiple implementations

  2. To enhance performance

  3. To enforce static methods

  4. To prevent method overriding

The correct answer is: To allow multiple implementations

Using interfaces allows for multiple implementations because classes can implement multiple interfaces, whereas they can only inherit from one base class. This allows for more flexibility and extensibility in the code. Options B, C, and D do not provide a valid reason for using interfaces over concrete base classes. Enhancing performance or enforcing static methods can be achieved with both interfaces and concrete base classes, and preventing method overriding can also be implemented with abstract classes. Therefore, options B, C, and D are incorrect as they do not provide a sole reason for choosing interfaces over concrete base classes.