Enum Inside

public class enuminside {
enum Color {GREEN(1),BLUE(2), RED(3);
int value;
Color(int value){  
this.value=value;
       }
}
public static void main(String args[]){
enuminside.Color c1= Color.GREEN;  //includes class name
enuminside.Color c2= Color.BLUE;
System.out.println(c1);  
System.out.println(c2.value);
}

}
Output:
GREEN
2

Enum Outside

enum Color {GREEN(1),BLUE(2), RED(3);
int value;
Color(int value){
this.value=value;
}
}
public class enumoutside{
public static void main(String args[]){
Color c1=Color.GREEN;  // only enum name
System.out.println(c1);
System.out.println(c1.value);
}
}

Output:
GREEN
1

 


Comments




Leave a Reply