class student implements Computer{ //继承student
public void print(){
System.out.println("我是一名学生!");
}
}
class teacher implements Computer{//继承teacher
public void print(){
System.out.println("我是一名老师!");
}
}
public class interfacebogs05 {
public static void main(String[] args) {
Computer com; //声明接口的接口变量
com = new teacher();//把使用的teacher类创建的对象的引用赋给声明接口的接口变量
com.print();//接口变量调用被类实现的接口中的方法时,就是通知相应的对象调用接口的方法
com = new student();
com.print();
}
}
class A implements Show{
public void show(){
System.out.println("我是A");
}
}
class B implements Show{
public void show(){
System.out.println("我是B");
}
}
class C{
public void g(Show s){//接口作为参数
s.show(); //show方法是现在将自己类创建的对象 的方法
}
}
public class interfacebogs06 {
public static void main(String[] args) {
C c = new C();
c.g(new A());//接口回调
c.g(new B());
}
}