panzerschreck
panzerschreck

Reputation: 3642

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 ?");
               }   
            }
     }

}

Upvotes: 2

Views: 105

Answers (2)

Jigar Joshi
Jigar Joshi

Reputation: 240860

 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()

Upvotes: 1

jweyrich
jweyrich

Reputation: 32240

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

Reference: Local and Anonymous Inner Classes

Upvotes: 4

Related Questions