class A {
public void method(I i) {
i.methodB();
}
}
//선언부와 구현을 분리.(껍데기와 알맹이를 분리하여 사용한다.)
//1. 메서드 선언(껍데기)
interface I{public abstract void method();}
//2. 메서드 구현(알맹이)
class B implements I {
public void method() {
System.out.println("B클래스의 메서드 in interface I");
}
}
class C implements I {
public void method() {
System.out.println("C클래스의 메서드 in interface I");
}
}
//main
public class InterfaceTest {
public static void main(String[] args) {
A a = new A();
//class A does not need to modify code.
a.method(new B());
a.method(new C());
//C c = new C();
//a.method(c);
}
}