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

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

Dive into the depths of Java with our quiz based on "Thinking in Java, Fourth Edition" by Bruce Eckel. Test your knowledge, solidify concepts, and prepare for certification with challenging questions and insightful feedback.

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


What method is implied to be added by the compiler to all enum classes?

  1. values()

  2. valueOf()

  3. toString()

  4. None of the above

The correct answer is: values()

The compiler adds the method values() to all enum classes by default. This method is used to create an array of all the enum constants defined inside the enum class. Option B, valueOf(), is incorrect because this method is used to return the enum constant value associated with the specified string if the values match. Option C, toString(), is incorrect because this method returns the string representation of the enum constant. Option D, None of the above, is incorrect because the compiler does add a method to enum classes, it just happens to be values(). So the correct answer is A, values().