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.
but dont you think that whether i declare the variable at //1 or //3 ..it
still would be viewed within the same namespace...at the method level..
So the scope that should be considered should be the whole block rather than the sequence being the deciding factor..
What do you say...
Joined: Jun 22, 2005
Hmm.... I understand your argument, but the very general assumption is, "flow of execution is alway from top to bottom"(from package statement then import to downside), and the other way round i.e bottom to top is not possible or I must say is simply unimaginable. And I guess it is on this basis, considering about the "i" (at line 3) at line 2 or at line 1 itself looks absurd. [ October 03, 2005: Message edited by: Akhil Trivedi ]
Joined: Jul 04, 2004
but the very general assumption is, "flow of execution is alway from top to bottom"
yes during execution ....we can say that line by line when it is executing... it will first see the i in the inner block and then when it comes out of it...this i is out of scope and the next i //3 comes into scope...
i in //3 is available throught the class...thats the opinion formed by looking at the class...Similiarly i in //1 is also available...in the scope..
In java we can use a variable only after declaration...So if we consider this....
//1 is uncommented....and //3 is commented then ..
..it is as per your explanation..
//3 is uncommented and //1 is commented then ..
the inner block i is out of scope after the block and outside the block ...another i is newly declared that is accessible for the rest of the program..
This code ..wil help in the direction..
If you comment the println ...it would compile fine..