This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Always remember First the Super Class is loaded Methods are invoked by Actual Object Typ Variable are called by Reference Typ
In ur code Object of Extension is made due to which it calls its constructor, an implicit super() causes to call Base class constructor.add(1) is called of Extension rather than Base(since objects are invoked by actual object type).It causes i=2 (since i is Zero before assingment).Control after assinging i=2 comes back to Base class constructor,finds no more statement therefor returns to Extension constructor here it finds another add(2) method,again Extension's add() is called rather than Base class.Now i gets the value of 6(Before assingment i was 2).Control comes back to the original statemnt in main where first time new Extension is called.Now bogo() is called which in turn call add(8) of Extension and finally i gets value of 22(Before assingment i was 6).And finally print is called which prints 22. Bye. Viki.
hi arathi, look at this current topic..its very interesting and cofusing as well. this will help u understanding how methods are invoked while dealing with parent/child classes. u can go here regards maulin