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

Explanation by: Dhruva Jagannath
Each enum constant overrides the abstract method; calling `A.show()` prints A.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.