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 is 'values()' in the context of enum classes?

  1. Instance method

  2. Class method

  3. Static method added by compiler

  4. None of the above

The correct answer is: Static method added by compiler

In the context of enum classes, 'values()' is a static method that is automatically added by the compiler. This method allows you to retrieve an array of all the possible values of the enum type. Option A is incorrect because 'values()' is not an instance method, meaning it does not require an instance of the enum class to be called. Option B is incorrect because it is not a class method that needs to be called on the class itself. Option D is incorrect because 'values()' is in fact a valid option.