InterviewSolution
Saved Bookmarks
| 1. |
Get the name of the Enum constant in Java |
|
Answer» The NAME of the enum constant is RETURNED by the method java.lang.Enum.name(). The method returns the name exactly as it was declared in the enum declaration. A program that DEMONSTRATES the java.lang.Enum.name() method is given as follows: enum Shape { CIRCLE, TRIANGLE, SQUARE, RECTANGLE; } public class Demo { public static void MAIN(String[] args) { Shape s = Shape.SQUARE; System.out.print("The name of enum constant is: " + s.name()); } }The output of the above program is as follows: The name of enum constant is: SQUARE |
|