Java Enums MCQs with answers Page - 5

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!

D

Dhruva Jagannath • 660 Points
Invincible

Q. What happens when you try to subclass an enum?

  • (A) It compiles but fails at runtime
  • (B) It compiles and runs
  • (C) Compile-time error
  • (D) It throws an exception

D

Dhruva Jagannath • 660 Points
Invincible

Q. What type of method is `values()` in an enum?

  • (A) Static method added by compiler
  • (B) Instance method
  • (C) Method from Enum class
  • (D) Custom method defined by user

D

Dhruva Jagannath • 660 Points
Invincible

Q. Can an enum be abstract?

  • (A) Yes, if it has abstract methods
  • (B) No, enums cannot be abstract
  • (C) Only in Java 15+
  • (D) Only if declared inside an interface

D

Dhruva Jagannath • 660 Points
Invincible

Q. What will this code print?

Code:
enum Test { A, B, C }
System.out.println(Test.A.compareTo(Test.C));
  • (A) -2
  • (B) 0
  • (C) 2
  • (D) -1

D

Dhruva Jagannath • 660 Points
Invincible

Q. Is it possible to override `toString()` in an enum?

  • (A) No
  • (B) Yes, but only once for all constants
  • (C) Yes, and even per constant using anonymous classes
  • (D) Only for enum fields, not constants

D

Dhruva Jagannath • 660 Points
Invincible

Q. Which enum constant syntax allows defining constant-specific behavior?

  • (A) NORMAL
  • (B) SPECIAL()
  • (C) SPECIAL { @Override method }
  • (D) static SPECIAL

D

Dhruva Jagannath • 660 Points
Invincible

Q. What happens if you call `name()` on a null enum reference?

  • (A) Returns null
  • (B) Throws NullPointerException
  • (C) Throws IllegalArgumentException
  • (D) Returns empty string

D

Dhruva Jagannath • 660 Points
Invincible

Q. Enums are best used when:

  • (A) Values may change dynamically
  • (B) You need a fixed set of constants
  • (C) You require user input
  • (D) You are building a REST API

D

Dhruva Jagannath • 660 Points
Invincible

Q. Which of the following can NOT be done in enum?

  • (A) Declare fields
  • (B) Create abstract methods
  • (C) Use anonymous classes
  • (D) Inherit another class

D

Dhruva Jagannath • 660 Points
Invincible

Q. What will this code do?

Code:
enum MyEnum {
  A { void show() { System.out.println("A"); } },
  B { void show() { System.out.println("B"); } };
  abstract void show();
}
MyEnum.A.show();
  • (A) Compile error
  • (B) Prints A
  • (C) Prints B
  • (D) Throws exception
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