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
  • Correct Answer - Option(A)
  • Views: 11
  • Filed under category Java
  • Hashtags: Java Enums

Explanation by: Dhruva Jagannath
`compareTo()` compares based on ordinal values. A (0) - C (2) = -2

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.