Online Java Compiler By
JavaTpoint.com
public class Enum_getDeclaringClassMethodExample2 { enum Herbivores{ Deer,Elephants,Horse,Sheep,Cow; } enum Carnivores{ Lion,Leopard,Wolf,lizard; } enum Omnivores{ Bear,Dog,Cat; } public static void main(String[] args) { //returns the class object corresponding to the enum constant Deer System.out.println("1. Deer is in "+Herbivores.Deer.getDeclaringClass()+" enum class"); //returns the class object corresponding to the enum constant Wolf System.out.println("2. Wolf is in "+Carnivores.Wolf.getDeclaringClass()+" enum class"); //returns the class object corresponding to the enum constant Bear System.out.println("3. Bear is in "+Omnivores.Bear.getDeclaringClass()+" enum class"); } }
Output