日期:2014-05-20 浏览次数:20876 次
public interface IShowable {
public void show();
}
public class Test {
public void showObject(IShowable obj){
obj.show();
}
class Employee implements IShowable{
@Override
public void show() {
System.out.println("我是员工");
}
}
public IShowable getManager(){
return new IShowable(){
@Override
public void show() {
System.out.println("我是管理员");
}
};
}
public static void main(String[] args) {
Test test = new Test();
IShowable showable1 = test.new Employee();
IShowable showable2 = test.getManager();
test.showObject(showable1);
test.showObject(showable2);
test.showObject(new IShowable() {
@Override
public void show() {
System.out.println("我是匿名内部类");
}
});
}
}