[접근 제한자] interface 인터페이스명 { ... }
public interface Runable {
void run(); // public abstract 생략 가능
}
// 인터페이스 구현 방법
public class Cat implements Runable {
...
@Override
public void run() {
...
}
}
다중 구현 가능
// 인터페이스의 다중 구현 시 콤마(,)로 구분한다.
public class Cat implements Runable, Swimable {
...
@Override
public void run() {
...
}
@Override
public void swim() {
...
}
}
인터페이스를 구현하는 클래스로 객체를 생성 후 구현된 메소드를 호출할 수 있음
Cat cat = new Cat();
cat.run();
cat.swim();
[접근 제한자] interface 하위인터페이스 extends 상위인터페이스1, 상위인터페이스2 { ... }
public interface Basic extends Runable, Swimable {
void eat();
}
public class Cat implements Basic {
...
@Override
public void eat() {
...
}
@Override
public void run() {
...
}
@Override
public void swim() {
...
}
}