标签:
interface People {
void peopleList();
}
class Student implements People {
public void peopleList(){
System.out.println("I’m a student.");
}
}
class Teacher implements People {
public void peopleList() {
System.out.println("I’m a teacher.");
}
}
public class Example {
public static void main(String args[]) {
People a; // 声明接口变量
a = new Student(); // 实例化,接口变量中存放对象的引用
a.peopleList(); // 接口回调
a = new Teacher(); // 实例化,接口变量中存放对象的引用
a.peopleList(); // 接口回调
}
}
标签:
原文地址:http://www.cnblogs.com/dolphin007/p/4452210.html