Created
April 14, 2020 02:17
-
-
Save SanthoshBabuMR/71f5952e7763e45a5042e00c3ffb5683 to your computer and use it in GitHub Desktop.
This file contains 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
// enum is private class with static final members | |
enum PersonType { | |
Men, | |
Women, | |
Transgender | |
} | |
class Person { | |
Person(String name, PersonType gender) { | |
this.name = name; | |
this.gender = gender; | |
} | |
String name; | |
PersonType gender; | |
} | |
public class Main { | |
public static void main(String[] args) { | |
Person person = new Person("foo", PersonType.Men); | |
System.out.println(String.format("person %s gender: ", person.name)); | |
System.out.println(person.gender); | |
System.out.println("\n"); | |
System.out.println("Looping all values in enum"); | |
// get all values in enum | |
PersonType[] values = PersonType.values(); | |
for(PersonType personType: PersonType.values()) { | |
System.out.println(personType); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment