开发者

What is this class(type) called in Java?

class X
{

    void method1(){}

    void method2(){}

}
class Y
{

     void someMethod()
     {

            /* 
               What is this type below called?
               Anonymous class or 
               Anonymous-Inherited class or what??? 
            */
            X xInstance = new X(){

               @Override
           开发者_开发百科    void method1()
               {
                    System.out.println("What kinda class is this ?");
               }   
            }
     }

}


It's an anonymous inner (or nested) class.

Reference: Local and Anonymous Inner Classes


 X xInstance = new X(){

               @Override
               void method1()
               {
                    System.out.println("What kinda class is this ?");
               }   
            }
     }

It is anonymous class. you have overriden implementation of method1()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜