I i = new A();
클래스 A의 객체를 인스턴스화하기 위해 인터페이스 I를 사용할 수있는 이유는 무엇입니까? obj = new A()를 사용해서는 안됩니까?클래스 인스턴스화 Java
interface I {
void f();
void g();
}
class A implements I {
public void f() { System.out.println("A: doing f()"); }
public void g() { System.out.println("A: doing g()"); }
}
class B implements I {
public void f() { System.out.println("B: doing f()"); }
public void g() { System.out.println("B: doing g()"); }
}
class C implements I {
// delegation
I i = new A();
public void f() { i.f(); }
public void g() { i.g(); }
// normal attributes
public void toA() { i = new A(); }
public void toB() { i = new B(); }
}
고마워요!
질문/문제가 무엇인지 명확하게 설명해 주시겠습니까? – beny23