interface Teachable{ void work();}
public class Programmer {
private String name;
public Programmer(){
};
public Programmer(String name){
this.name = name;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
//
public void work(){
System.out.println(name+"来自"+getClass());
}
}
创建子类和子类内部类
public class TeachableProgrammer extends Programmer {
public TeachableProgrammer(){
}
public TeachableProgrammer(String name){
super(name);
}
private void teach(){
System.out.println(getName() + "来自接口");
}
//内部类
private class Clourse implements Teachable {
//来自接口的
public void work(){
teach();
}
}
public Teachable getCallbackReference(){
return new Clourse();
}
}
调用和Debug
public class TestTeachableProgrammer {
public static void main (String [] args) {
TeachableProgrammer tp = new TeachableProgrammer("你");
tp.work(); //来自父类
tp.getCallbackReference().work(); //来自接口实现
}
}