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.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Forward Refrence Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Forward Refrence" Watch "Forward Refrence" New topic
Author

Forward Refrence

rohan yadav
Ranch Hand

Joined: Oct 13, 2009
Posts: 156


Why the output of above program is 0


Sage of The Monstrous Toad of Mount Myoboku
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
because when you call the getI() the i is initialised to its default value...
rohan yadav
Ranch Hand

Joined: Oct 13, 2009
Posts: 156
But i thought that wen getI() method return i it would have been initialized to 5, because int i = 5; statement would be executed first.
Am i right??
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
hey when int j is being executed the line int i=5 isnt executed....that is why the jvm only knows about the variable i...so default value
rohan yadav
Ranch Hand

Joined: Oct 13, 2009
Posts: 156
ohhhhhh got it
Ajit Sawant
Ranch Hand

Joined: Nov 26, 2008
Posts: 33
Concept: The initalization of the variable happen in the order in which the variable appear.
In this case when j is initialized the value of i is initialized to 0.
 
Have you checked out Aspose?
 
subject: Forward Refrence
 
It's not a secret anymore!