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

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

Prepare for the Java Mastery Quiz with engaging questions and essential hints designed to enhance your understanding of 'Thinking in Java'. Get ready to solidify your programming skills!

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.