Hi Yaun.
class test {
public void doo() {
System.out.print("doo");
}
public static void main(String [] args) {
test n = new test() {}; //why correct?
n.doo();}
}
}
The syntax .
new test() {}; creates a very simple anonymous inner class. Technically, it creats a
subclass instance of test, albeit one that does not override any of the methods of the test class.
So this syntax is effectively redundant when used in this way. To Make it more meaningful you could override the
doo() method when you instantiate. Example :
And given the above change,
n.doo() will now print "daa" instead of "doo".
Hope this helps
