public class Test{
public static void main(String [] args){
TheInterface a = new A();
TheInterface b = new B();
choose(a);
choose(b);
}
public static void choose(TheInterface x){//若这里不申明为 static 则error为无法从静态上下文中引用
//非静态方法 ?? 我不明白是什么意思..
x.print();
}
}
interface TheInterface{
void print();
}
class A implements TheInterface{
public void print(){
System.out.println("this is A");
}
}
class B implements TheInterface{
public void print(){
System.out.println("this is B");
}
}