com.javatransport;
import com.javainterface.*;
public class Test {
public static void main(String[] args) {
MyImpl1 s1 = new MyImpl1();
MyImpl2 s2 = new MyImpl2();
Test.useMyInterface(s1);
Test.useMyInterface(s2);
}
public static void useMyInterface(MyInterface ex1) {
if(ex1 instanceof MyImpl1) {
ex1.method1();
//System.out.println(“MyImpl1的对象所属的类”);
}
if(ex1 instanceof MyImpl2) {
System.out.println(“MyImpl2的对象所属的类”);
}
}
}