Skip to content

Instantly share code, notes, and snippets.

@wkdalsgh192
Last active September 26, 2021 14:26
Show Gist options
  • Save wkdalsgh192/1ad102c5570f0979ef56e5355e313b22 to your computer and use it in GitHub Desktop.
Save wkdalsgh192/1ad102c5570f0979ef56e5355e313b22 to your computer and use it in GitHub Desktop.
class Day {
public final static Day MONDAY = new Day();
public final static Day TUESDAY = new Day();
public final static Day WEDNESDAY = new Day();
}
class Month {
public final static Month JANUARY = new Month();
public final static Month FEBRUARY = new Month();
public final static Month MARCH = new Month();
}
public class EnumExample4 {
public static void main(String[] args) {
// an compile error occurs at the if statement as we are trying to compare two different types
if (Day.MONDAY == Month.JANUARY) {
System.out.println("Both are same!");
}
Day day = Day.MONDAY;
switch (day) {
case Day.MONDAY:
System.out.println("Mondays are bad");
break;
case Day.TUESDAY:
System.out.println("Tuesdays are still bad");
break;
case Day.WEDNESDAY:
System.out.println("Wednesdays are so-so");
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment