추상 매서드의 집합 →인터페이스의 본질
구현된 것이 하나도 없는 설계도. 껍데기(모든 맴버가 public)
추상클레스와 인터페이스의 차이점
추상클래스는 추상 메서드를 가지고 있는 클래스 ( iv를 가질 수 있다 )
abstract class Unit{
int x,y; //iv 선언
abstract void move(int x, int y);
void stop(){/*현제위치에 정지*/}
}
인터페이스는 아무것도 구현된것이 없다. ( 맴버변수를 가질 수 없다 )
interface Inter {
public static final 타입 상수이름 = 값;
public abstract 메서드이름(매개변수목록);
}
인터페이스에서는 public static final을 생략이 가능하다.
컴파일하면 자동으로 붙어서 연산이 된다.
interface Fightable extends Movable, Attackable {}
interface Movable {
/** 지정된 위치(x,y)로 이동하는 기능의 메서드**/
void move(int x, int y);
}
interface Attackable{
/** 지정한 대상(u)를 공격하는 기능의 메서드 **/
void attack(Unit u);
}
인테페이스에 정의된 추상 메서드를 완성하는 것 implements 키워드를 사용한다.
class Fighter implements Fightable {
publi**/c void move(int x, int y) {/*구현내용*/ }
public void attack(Unint u) {/*구현내용*/ }
}