Anonymous class with interface

后端 未结 4 1931
挽巷
挽巷 2021-01-16 14:24

I am confused about the concept of interface when dealing with anonymous inner class. As far as I know that you can\'t instantiate an interface in Java, so the following sta

4条回答
  •  长情又很酷
    2021-01-16 15:07

    You are creating a class and implementing the interface when working with anonymous class.you can override the methods or implement the method inside the anonymous class

        A a= new A(){ 
    
                   }; 
    

    Here a is a reference variable of type A which is referring not to A but to an object of class which implement A who doesn't have a name

提交回复
热议问题