Java Enum name() MethodThe name() method of Enum class returns the name of this enum constant same as declared in its enum declaration. The toString() method is mostly used by programmers as it might return a more easy to use name as compared to the name() method. SyntaxReturn ValueThe name() method returns the name of this enum. Example 1Output: 1. Cow is in class com.javaTpoint.Enum_nameMethodExample1$Herbivores enum class 2. Leopard is in class com.javaTpoint.Enum_nameMethodExample1$Carnivores enum class 3. Bear is in class com.javaTpoint.Enum_nameMethodExample1$Omnivores enumclas Example 2Output: Types of Triangles: Right_Angle_Triangle is a triangle in which one angle is 90 degree. Obtuse_Angled_Trianlge is a triangle in which one angle is greater than 90 degree. Acutee_Angled_Trianlge is a triangle in which one angle is less than 90 degree. Example 3Output: Circles has 0 sides. Triangles has 3 sides. Quadrilaterals has 4 sides. Pentagon has 5 sides. Next TopicJava-enum-ordinal-method |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India