wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes  scope of the variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
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: 6109
    
    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 X Peterson
Whizlabs Java Support
Ranch Hand

Joined: Feb 26, 2013
Posts: 158
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.
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1558
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: 1157

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: 1157

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: 40052
    
  28
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://aspose.com/file-tools
 
subject: scope of the variable