The following program when run will product stackoverflow as output.
I want to know what is happening in the line where a TestA is being instantiated.
interface TestA { String toString(); }
class Test
{
public static void main(String[] args)
{
// whats going on in this line ???
System.out.println(new TestA() {public String toString() { return "stackoverflow"; } });
}
}
You are instantiating an anonymous class, that implements the
TestAinterface.This technique is very useful for e.g. event listeners in GUI programming, since it saves you from creating a bunch of named single-use classes.