Java Enums MCQs with answers Page - 3

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.43K Points
Coach

Q. Can enum constants override methods in Java?

  • (A) No, enums are constant and cannot override anything
  • (B) Yes, using anonymous class body
  • (C) Only if declared abstract
  • (D) Only static methods can be overridden

A

Admin • 828.43K Points
Coach

Q. What will the following code print?

Code:
enum Direction { NORTH, SOUTH, EAST, WEST }
System.out.println(Direction.NORTH == Direction.valueOf("NORTH"));
  • (A) true
  • (B) false
  • (C) Compile-time error
  • (D) Runtime exception

A

Admin • 828.43K Points
Coach

Q. What happens if you call `valueOf()` with a name that doesn’t exist in the enum?

  • (A) Returns null
  • (B) Returns the first enum constant
  • (C) Throws IllegalArgumentException
  • (D) Throws NullPointerException

A

Admin • 828.43K Points
Coach

Q. In which case is the `values()` method available for an enum?

  • (A) Always, as part of java.lang.Enum
  • (B) Only if explicitly defined
  • (C) Available as a compiler-generated static method
  • (D) Never available

A

Admin • 828.43K Points
Coach

Q. Can enums be declared inside a class in Java?

  • (A) Yes, only if the class is static
  • (B) Yes, both static and non-static classes
  • (C) No, enums must be top-level only
  • (D) Only inside abstract classes

A

Admin • 828.43K Points
Coach

Q. Which method is implicitly overridden in every enum constant?

  • (A) toString()
  • (B) hashCode()
  • (C) equals()
  • (D) compareTo()

A

Admin • 828.43K Points
Coach

Q. How do you define custom fields for enum constants?

  • (A) By using static variables only
  • (B) By passing parameters to the enum constructor
  • (C) By overriding the enum class
  • (D) You can't define fields in enums

A

Admin • 828.43K Points
Coach

Q. What is the visibility of an enum constructor in Java?

  • (A) public
  • (B) protected
  • (C) private or package-private
  • (D) Any access modifier

A

Admin • 828.43K Points
Coach

Q. Can an enum extend another enum in Java?

  • (A) Yes, if the base enum is abstract
  • (B) Yes, using inheritance
  • (C) No, enums cannot extend any class except Enum
  • (D) Yes, with final keyword

A

Admin • 828.43K Points
Coach

Q. Which method returns the position of an enum constant in its declaration?

  • (A) ordinal()
  • (B) position()
  • (C) index()
  • (D) value()
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