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.


Can EnumMap keys be from different enums?

  1. Yes

  2. No

The correct answer is: No

A Java EnumMap is a specialized Map implementation designed specifically to work with enums as keys. When creating an EnumMap, you must specify which enum type will be used as the key. This means that all keys in the EnumMap must come from the same enum type. Therefore, the correct answer is no, EnumMap keys cannot come from different enums.