package gee;
class A{
void a(){
System.out.println(1);
}
}
class B{
void a(){
System.out.println(2);
}
}
class C{
void a(){
System.out.println(3);
}
}
class D{
public static void test(Object o){
if(o instanceof A)
((A)o).a(); ------------->>> test 메서드를 쭐이야함
else if(o instanceof B)
((B)o).a();
else
((C)o).a();
}
public static void main(String args[]){
test(new A());
test(new B());
test(new C());
}
}
a, b, c클래스들을 전부 하나의 인스턴스로 묶고 그 인스턴스에서 a()메소드 정의해놓으면 instanceof로 비교안하고 바로 인터페이스로 형변환해서 a()호출 가능