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 1Test it NowOutput: 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 2Test it NowOutput: 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 3Test it NowOutput: Circles has 0 sides. Triangles has 3 sides. Quadrilaterals has 4 sides. Pentagon has 5 sides.
Next TopicJava Enum
|