Skip to content

Instantly share code, notes, and snippets.

@Vishal1297
Created August 6, 2020 18:17
Show Gist options
  • Save Vishal1297/aadb36fffbebae2f6abdd599eefd1d2c to your computer and use it in GitHub Desktop.
Save Vishal1297/aadb36fffbebae2f6abdd599eefd1d2c to your computer and use it in GitHub Desktop.
Class As A Enum In Java
public class Color {
public static final Color RED = new Color("RED");
public static final Color WHITE = new Color("WHITE");
public static final Color BLUE = new Color("BLUE");
public static final Color GREEN = new Color("GREEN");
private String color;
static {
System.out.println(1);
}
{
System.out.println(2);
}
private Color(String color){
System.out.println(3);
this.color = color;
System.out.println(color);
}
@Override
public String toString() {
return this.color;
}
public static void main(String[] args) {
Color color = Color.BLUE;
System.out.println(color);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment