
여러 짧은 소스들을 다뤘고 Annotation을 이용하여 내가 implement를 사용했을때
설계를 지켰는지 알 수 있는 인터락 방법을 인지함
그리고 역시 enum은 자바에서도 정수화 되어 switch와 호환된다.
package dive.d03anonymousclass.eg03withanomymous_Animals;
interface Pets
{
void Cry();
}
public class Main
{
public static void main(String[] args)
{
Pets Dogs = new Pets()
{
public void Cry()
{
System.out.println("멍멍");
}
};
Dogs.Cry();
Pets Cats = new Pets()
{
public void Cry()
{
System.out.println("야옹");
}
};
Cats.Cry();
}
}
package dive.d04constant.eg01creats;
class AppConfig //설정(configuratioin)
{
//데이터 베이스 주소
static final String DB_URL = "localhost:3306/mydb";
//API 주소
static final String API_URL = "https://example.com.api";
//최대 로그인 횟수
static final int MAX_LOGIN_ATTEMPTS = 5;
}
public class Main
{
public static void main(String[] args)
{
//static 변수는 클래스 자체로 접근합니다.
System.out.println(AppConfig.DB_URL);
System.out.println(AppConfig.API_URL);
System.out.println(AppConfig.MAX_LOGIN_ATTEMPTS);
}
}
package dive.d05enum.eg02usage;
//자바에서는 enum도 일종이 클래스이다.
enum Day
{
SUN,
MON,
TUE,
WED,
THU,
FRI,
SAT
};
public class Main
{
public static void main(String[] args)
{
Day today = Day.FRI;
switch(today)
{
case Day.SUN:
System.out.println("일요일입니다.");
break;
case Day.MON:
System.out.println("월요일입니다.");
break;
case Day.TUE:
System.out.println("화요일입니다.");
break;
case Day.WED:
System.out.println("수요일입니다.");
break;
case Day.THU:
System.out.println("목요일입니다.");
break;
case Day.FRI:
System.out.println("금요일입니다.");
break;
}
}
}