interface InterfaceName {
public static final typeFinalName = value;
public abstract methodName(Object... paramList);
}
* interface에서 public, abstract, final 생략 가능
interface 인터페이스이름{
public static final 타입 상수이름 = 값;
public abstract 메서드이름(매개변수목록); //모든 인터페이스의 맴버는 public+
//메서드는 추상메서드(abstract)
// 몸통{}이 없음
class 클래스이름 implements 인터페이스이름 {
// 인터페이스에 정의된 추상메서드를 모두 구현해야 함
}
class Fighter implements Fightable{
public void move(int x, int y) { }
public void attack(Unit u)
abstract class Fighter implements Fightable{
public void move(int x, int y){ /*내용 생략*/
}
//추상 클래스 구현
class AudioPlayer extends Player{
void play(int pos){ }
void stop(){ }
}
// 인터페이스 구현
class Fighter implements Fightable{
public void move(int x, int y){ }
public void attack(Unit u){ }
}
공통점 : 갖고있는 추상매서드를 완성해줌 (미완성 설계도를 완성시킴)
차이점 : 인터페이스는 인스턴스 변수를 가질 수 없다.
(== 객체 생성을 하지 못하니까
== 인스턴스를 생성할 수 없으니까
== 생성자 없음 == 인스턴스 변수도 생성되지 못함).
오로지 추상매서드 만으로 구성되어있음. 구현된 것이 전혀 없음.