There are several things to look at. First, on line 06 below, go() is called
on the anonymous class created by new. Okay so far?
Then looking at the definition of Water, its drinkWater() method immediately calls
drink() on an Interf object that is passed in. The key to the puzzle is to figure out
how this Interf object is created.
Notice below that the parameter passed to drinkWater() continues all the way from
the 'new' on line 02 through line 06. The drinkWater() call ends with ); on line 06.Below again is the type Interf parameter from above. Line 07 starts a rewritten version
that illustrates what is happening.So you can 'new' an interface, creating an anonymous class, if you implement the interface's
methods in this way. Right in the call parameter list, Interf is implemented by a 'no-name'
class and then the 'no-name' class is instantiated as a type Interf object. Pretty cool, ey?
BEE MBA PMP SCJP-6
Joined: Aug 27, 2009
Thanks Jim for the elaborative reply
I used the correct word i think in the last post i.e "MAGIC"