开发者

What is this class(type) called in Java?

开发者 https://www.devze.com 2023-02-08 05:16 出处:网络
class X { void method1(){} void method2(){} } class Y { void someMethod() { /* What is this type below called?
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

精彩评论

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