package com.java1.day18;
public class FighterTextEx4 {
public static void main(String[] args) {
Fighter11 f = new Fighter11();
if (f instanceof Unit11) {
System.out.println("f는 Unit클래스의 자손입니다.");
}
if (f instanceof Fightable11) {
System.out.println("f는 Fightable인터페이스를 구현했습니다.");
}
if (f instanceof Movable11) {
System.out.println("f는 Movable인터페이스를 구현했습니다.");
}
if (f instanceof Attackable11) {
System.out.println("f는 Attackable인터페이스를 구현했습니다.");
}
if (f instanceof Object) {
System.out.println("f는 Object클래스의 자손입니다.");
}
}
}
class Fighter11 extends Unit11 implements Fightable11 {
@Override
public void move(int x, int y) {}
@Override
public void attack(Unit11 u) { }
}
class Unit11 {
int currentHP;
int x;
int y;
}
interface Fightable11 extends Movable11, Attackable11 { }
interface Movable11 { void move(int x, int y); }
interface Attackable11 {
void attack(Unit11 u);
}
출력결과
f는 Unit클래스의 자손입니다.
f는 Fightable인터페이스를 구현했습니다.
f는 Movable인터페이스를 구현했습니다.
f는 Attackable인터페이스를 구현했습니다.
f는 Object클래스의 자손입니다.