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.


What change did Java SE5 introduce regarding the use of interfaces for constants?

  1. Allowed methods to be defined

  2. Disallowed this practice

  3. Replaced with enums

  4. Introduced default methods

The correct answer is: Replaced with enums

The correct answer is C replaced with enums. This is because prior to Java SE5, constants were defined in interfaces and had to be implemented by classes. This was not an optimal structure as classes could not inherit from multiple classes but could implement multiple interfaces. Therefore, Java SE5 introduced enums which are specially designed classes that can be used to define constants, removing the limitation of classes only being able to inherit from one class. Options A and D are incorrect because while Java SE5 did introduce the concept of default methods for interfaces, this was not in relation to constants. Option B is incorrect because Java SE5 did not disallow the practice of defining constants in interfaces, it simply introduced an alternative and more efficient option.