| 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
|
|
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
|
|
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.
|
 |
 |
|
|
subject: scope of the variable
|
|
|