Unit u = new Fighter();
조상클래스 자손객체
Fightable f = new Fighter();
인터페이스 자손객체
interface Fightable {
void move(int x, int y);
void attack(Fightable f);
} 2개만 사용가능 , 1.인터페이스 타입 매개변수는 인터페이스 구현한 클래스의 객체만 가능
f.move(100,200);
f.attack(new Fighter());
Fightable인터페이스를 구현한 클래스의 인스턴스를 반환
Fightable method() {
Fighter f = new Fighter();
return f;
} 2. 인터페이스를 메서드의 리턴타입으로 지정할 수 있다.
Fightable f = (method() 같은말)new Fighter();
인터페이스의 모든 메서드는 public abstract. 예외없이
(public) void move(int x, int y); // public abstract가 생략됨