Java Enum getDeclaringClass() Method

The getDeclaringClass() method of Enum class returns the object of Class representing the enum type of this enum constant.

Suppose there are two enum constants e1 and e2, they are of the same enum type if

Syntax

Parameters

NA

Return Value

The getDeclaringClass() method returns the Class object representing the enum type of this enum's constant.

Example 1

Output:

classcom.javaTpoint.BodyPart

Example 2

Output:

1. Deer is in class com.javaTpoint.Enum_getDeclaringClassMethodExample2$Herbivores enum class
2. Wolf is in class com.javaTpoint.Enum_getDeclaringClassMethodExample2$Carnivores enum class
3. Bear is in class com.javaTpoint.Enum_getDeclaringClassMethodExample2$Omnivores enum class