Last active
September 26, 2021 14:26
-
-
Save wkdalsgh192/1ad102c5570f0979ef56e5355e313b22 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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