JAVA/예제
[JAVA] ch07-20. 객체 지향 20
밍글링글링
2017. 8. 22. 11:46
728x90
public class Ex20 {
public static void main(String[] args){
Fighter fighter = new Fighter();
if(fighter instanceof Thing) //fighter는 Thing에 소속되어있다.. (true)이므로 출력.
System.out.println("fight instanceof Thing");
if(fighter instanceof Fightable) //fighter is instance of Fightable.
System.out.println("fight instanceof Fightable");
if(fighter instanceof Movable)
System.out.println("fight instanceof Movable");
if(fighter instanceof Attackable)
System.out.println("fight instanceof Attackable");
if(fighter instanceof Object)
System.out.println("fight instanceof Object");
}
}
class Thing{
int hp;
int x;
int y;
}
interface Movable{
void move(int x, int y);
}
interface Attackable{
void attack(Thing thing); //선언부만 사용
}
interface Fightable extends Movable, Attackable{}
class Fighter extends Thing implements Fightable{
public void move(int x, int y) {}
public void attack(Thing thing) {}
}
728x90