This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Originally posted by Paresh Joshi: and about "0" you're initializing it by calling method ... but at that time compiler doesnt know about that method. so by default members of classes in java intializes to its default value.
(i.e. 0 for integer)[/QB]
Actually, the compiler does now about that method.
Here's the order of execution: 1) a = f(); However, f returns b because it uses the actual implementation of f() of the object, not the reference. The object is a Sub. b has not been initialized so it is 0. a will become 0. 2) b = 2; 3) a is retrieved. It is still 0 after step 1. 4) f() is called on the sub, which returns b which is 2.