Java中接口回调
程序员文章站
2022-03-23 17:04:13
...
日期:2020/1/14
功能:实现java中的接口回调
IDE:Intellij IDEA
接口回调类似之前的上转型对象,接口回调表示接口的实例化变量存放实现该接口的类的对象的引用
接口回调可以让接口的实例化变量调用实现该接口的自定义类中的方法
package testDemo;
interface People{
void peopleList();
}
class StudentPeople implements People{
@Override
public void peopleList() {
System.out.println("我是学生");
}
}
class TeacherPeople implements People{
@Override
public void peopleList() {
System.out.println("我是老师");
}
}
public class BackInterface {
public static void main(String[] args){
People people;
people = new StudentPeople();
people.peopleList();
people = new TeacherPeople();
people.peopleList();
}
}
上一篇: 创客和ABB工业机器人亲密接触