匿名内部类

public interface ICan{
    void eat();
}

public static void main(String[] args){

    //在代码量少,只需一个实例的时候就可以运用匿名内部类
    ICan ican = new ICan(){
        public void eat(){
            System.out.println("i can eat");
        }
    }
    
    
}
  1. 方便,快捷
posted @ 2018-05-07 22:19  话少心在  阅读(100)  评论(0编辑  收藏  举报