public class DayType {
public static final int sunday = 0;
public static final int monday = 1;
public static final int tuesday = 2;
public static final int wendesday = 3;
public static final int thursday = 4;
public static final int friday = 5;
public static final int saturday = 6;
}
public class Exam {
public static void main(String[] args) {
int today = DayType.SUNDAY;
System.out.println(today);
if (today==DayType.SUNDAY){
System.out.println("์ค๋์ ์ผ์์ผ!");
}
}
}
->0
์ค๋์ ์ผ์์ผ!
public enum DayType {
SUNDAY, MONDAY, TUESDAY, WENDESDAY, THURSDAY, FRIDAY, SATURDAY
}
public static void main(String[] args) {
DayType day = DayType.SUNDAY;
System.out.println(day);
}
->SUNDAY
public class DAY {
private DayType dayType;
public DayType getDayType() {
return dayType;
}
public void setDayType(DayType dayType) {
this.dayType = dayType;
}
}
public class Exam {
public static void main(String[] args) {
DAY day = new DAY();
day.setDayType(DayType.SUNDAY);
System.out.println(day.getDayType());
}
}
->SUNDAY
public static void main(String[] args) {
DayType day = DayType.SUNDAY;
switch (day){
case SUNDAY :
System.out.println("์ผ์์ผ ์ข์~");
break;
default:
System.out.println("์ผ์์ผ์ด ์๋์ผ...");
}
}
->์ผ์์ผ ์ข์~
enum DayType {
SUNDAY, MONDAY, TUESDAY, WENDESDAY, THURSDAY, FRIDAY, SATURDAY;
private DayType(){
System.out.println("1์ฃผ์ฐจ");
}
@Override
public String toString() {
return "์ผ์์ผ์ด ์ข๋ค..";
}
}
public class Exam {
public static void main(String[] args) {
System.out.println(DayType.SUNDAY);
}
}
->1์ฃผ์ฐจ
1์ฃผ์ฐจ
1์ฃผ์ฐจ
1์ฃผ์ฐจ
1์ฃผ์ฐจ
1์ฃผ์ฐจ
1์ฃผ์ฐจ
์ผ์์ผ์ด ์ข๋ค..
public static final DayType SUNDAY = new DayType();
public static final DayType MONDAY = new DayType();
...
public static final DayType SATURDAY = new DayType();
enum Gender {
MAN(1),WOMAN(2);
int idNumber;
private Gender(int idNumber){
this.idNumber = idNumber;
}
@Override
public String toString() {
return "My idNumber is " + idNumber;
}
}
public class Exam {
public static void main(String[] args) {
System.out.println(Gender.MAN);
}
}
->My idNumber is 1
Enum๊ฐ์ ์์์ด๊ธฐ ๋๋ฌธ์ ๋ฉ๋ชจ๋ฆฌ์ ๋ฑ ํ๊ฐ๋ง ์ฌ๋ผ๊ฐ๋ค.
public static void main(String[] args) {
DayType dayType1 = DayType.SUNDAY;
DayType dayType2 = DayType.SUNDAY;
System.out.println(dayType1 == dayType2);
}
->true
public static void main(String[] args) {
EnumMap emap = new EnumMap(DayType.class);
emap.put(DayType.SUNDAY, "์ผ์์ผ์ด ์ต๊ณ ์ผ ์ง์ง.. ์ผ์์ผ์ ์ ์ด์ผ..");
emap.put(DayType.MONDAY, "์์์ผ...?์ผใ
กใ
ก์ฝ ์์์ผ...");
emap.put(DayType.FRIDAY, "์ผ์ฃผ์ผ ์ค ๊ฐ์ฅ ์ค๋ ๋ ์์ผ? ๊ธ์์ผ์ด์ง~");
System.out.println(emap.get(DayType.SUNDAY));
}
->์ผ์์ผ์ด ์ต๊ณ ์ผ ์ง์ง.. ์ผ์์ผ์ ์ ์ด์ผ..
public interface DAY {
public void print();
}
enum DayType implements DAY{
SUNDAY, MONDAY, TUESDAY, WENDESDAY, THURSDAY, FRIDAY, SATURDAY;
@Override
public void print() {
System.out.println("์ธํฐํ์ด์ค๋ ๊ตฌํ๋ฐ์ ์ฌ์ฉ ๊ฐ๋ฅ!");
}
}
enum DayType{
SUNDAY{
public void print(){
System.out.println("์ผ์์ผ!!!!");
}
}, MONDAY{
public void print(){
System.out.println("์์์ผ....");
}
},FRIDAY{
public void print(){
System.out.println("๊ธ์์ผ~~~");
}
};
public abstract void print();
}