aspose file tools
The moose likes Beginning Java and the fly likes  scope of the variable Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark " scope of the variable" Watch " scope of the variable" New topic
Author

scope of the variable

veena bijur
Ranch Hand

Joined: May 16, 2011
Posts: 67

scope of the variable means what?

Please explain.

Thanks
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 5901
    
    6

Please SearchFirst(←click).

Here's a link to pasting your exact question into Google:
http://www.google.com/search?q=scope+of+the+variable+means+what?
James Peterson
Whizlabs Java Support
Ranch Hand

Joined: Feb 26, 2013
Posts: 105
Hi veena bijur,


Variable scope refers to the accessibility of a variable.

Example:
public class MainClass {

public static void main(String[] args) {
for (int x = 0; x < 5; x++) { // beggining of scope for variable x
System.out.println(x);
}//end of scope for variable x
}
//here you cant access x
}


In the above example if you observe variable x can be accessed only with in the for loop because the scope of x is with in the loop.

Whizlabs-Software, OCAJP 7 , SCJA 6 , SCJP 6 , OCPJP 7 , OCPJP 7- Upgrade ,SCWCD 5 ,OCEJWCD 6 ,SCBCD 5 ,SCEA 5 , PMP , PMI-ACP
Unconditional 100% Test PASS Guarantee!
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1493
scope means availability or visibility or accessibility.


Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1142

Welcome to the ranch Veena. Are you absolutely new to the Java language? Where are you learning from? Which book?


~ Mansukh
veena bijur
Ranch Hand

Joined: May 16, 2011
Posts: 67
Thanks for the reply. i got it.

sir,
i am not new to Java ,just from interview point of view learning.

when such question asked was stuck.
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1142

Don't "sir" me Veena. I am yet to be knighted by the Queen of England. Your doubt sounded like a novice's. Hence, I asked. Anyways, let us know in case you are stuck. We are here to help.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32712
    
    4
Akhilesh Trivedi wrote:scope means availability or visibility or accessibility.
. . .
No it doesn’t. Visibility and accessibility are different from scope. It might mean availability, but I would go farther and say it means the very existence of the variable. Fields are always in scope for the whole class, so that problem does not exist there. But in a loop, like this one…the value of i is put on the stack, and at the end of the first loop, all records of what is on the stack may be gone. So the value of i can be deleted from the stack, or more precisely replaced by another value. Or, to put it another way, when the scope of i is finished, its very existence is finished too.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: scope of the variable
 
Similar Threads
how to access variables in static ini blocks
Error in class level variable
My arrays are getting destroyed??!
do while error
"cannot find symbol" error