Java Enums MCQs with answers Page - 4

You will find multiple-choice questions (MCQs) related to #Java Enums here. Go through these questions to prepare effectively for your upcoming exams and interviews.

To view the correct answer for any question, simply click the "Show Answer" button.

Have a question to share? Click on "Add Question" to contribute!

A

Admin • 828.03K Points
Coach

Q. Can enum constants have their own method implementations?

  • (A) No, all methods are shared
  • (B) Yes, using anonymous class bodies per constant
  • (C) Only static methods can be overridden
  • (D) Only if the enum is final

D

Dhruva Jagannath • 660 Points
Invincible

Q. Which of the following is the correct way to iterate over an enum in Java?

  • (A) Using a for-each loop on Enum.values()
  • (B) Using a while loop on Enum.length()
  • (C) Using Enum.iterator()
  • (D) Using Enum.getList()

D

Dhruva Jagannath • 660 Points
Invincible

Q. What does the `ordinal()` method of an enum return?

  • (A) The name of the constant
  • (B) The position of the constant in the enum declaration
  • (C) The hashcode of the constant
  • (D) The string value of the enum

D

Dhruva Jagannath • 660 Points
Invincible

Q. What will this code print?

Code:
enum Level { LOW, MEDIUM, HIGH }
System.out.println(Level.HIGH.ordinal());
  • (A) 1
  • (B) 2
  • (C) HIGH
  • (D) 0

D

Dhruva Jagannath • 660 Points
Invincible

Q. Can enum constants be compared using '=='?

  • (A) No, '==' only works with primitives
  • (B) Yes, enum constants are singleton and can be compared with '=='
  • (C) Only if you override equals()
  • (D) Only in Java 11 and above

D

Dhruva Jagannath • 660 Points
Invincible

Q. What is the default return value of the `toString()` method in enums if not overridden?

  • (A) The ordinal
  • (B) The enum class name
  • (C) The constant name
  • (D) null

D

Dhruva Jagannath • 660 Points
Invincible

Q. What will happen if you use `switch-case` with an enum and forget one constant?

  • (A) Compile-time error
  • (B) Runtime exception
  • (C) Nothing, it will skip unmatched cases
  • (D) The switch will repeat the last matched case

D

Dhruva Jagannath • 660 Points
Invincible

Q. What kind of fields can enums have?

  • (A) Only final fields
  • (B) Only static fields
  • (C) Any type of field
  • (D) Enums cannot have fields

D

Dhruva Jagannath • 660 Points
Invincible

Q. How is an enum constructor called?

  • (A) By new keyword
  • (B) Automatically by the JVM for each constant
  • (C) Manually by the programmer
  • (D) By reflection

D

Dhruva Jagannath • 660 Points
Invincible

Q. Which of these is NOT true about enums in Java?

  • (A) They can implement interfaces
  • (B) They can extend classes
  • (C) They can have methods
  • (D) They are final by default
What's Tag

As you may know, questions are organized under broad categories. Each category can include various types of questions. For example, the "History" category might contain questions about the Revolt of 1857, Shivaji Maharaj, Ancient History, Buddhism, and more.

To further refine this organization, we've introduced tags, which act as sub-categories to group questions more specifically.

Verified users can add tags to any question. If you have any suggestions regarding this system, we'd love to hear from you. Contact Us

Learn More