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()
精彩评论