interface Teach{
/**
*父类提供一个抽象方法让子类以多态的形式体现
*/
public void teachLession();
}
/**
*创建JavaTeacher
*/
class JavaTeacher implements Teach{
String name;
public void teachLession(){
System.out.println(name+"正在讲多态");
}
}
/**
*创建PHPTeacher
*/
class PHPTeacher implements Teach{
String name;
public void teachLession(){
System.out.println(name+"正在讲PHP课程 ");
}
}
class Leader{
public void CheckTeacher(Teach t){
String teacher = null ;
if(t instanceof JavaTeacher){
teacher = "java老师";
}else {
teacher = "PHP老师";
}
System.out.println("开始考察");
t.teachLession();
System.out.println("结束考察");
}
}
class TestTeacher1{
public static void main(String []args){
JavaTeacher jt = new JavaTeacher();
jt.name = "kim哥";
PHPTeacher pt = new PHPTeacher();
pt.name = "chueng";
Leader leader = new Leader();
leader.CheckTeacher(jt);
leader.CheckTeacher(pt);
}
}