我偶然發現了這個肯定,它改變了我對Java範圍的概念。 C 我的概念曾經是「範圍是指可以訪問聲明變量的代碼段」有沒有人有任何更明確的引用?當一個變量超出範圍時,它永遠不能回到範圍
例子:
public static void main(String[] args) {
int x = 5;
amIOutOfScope();
System.out.println("Am in the x variable scope again?");
}
private static void amIOutOfScope(){
System.out.println("am I outta scope? I can't access x here, Does it mean I'm outta scope?");
//System.out.println(x);//wrong as hell
}
這肯定是真的嗎?如果是這樣,當你進入amIOutOfScope()方法時,你是否超出了變量x的範圍?你會怎麼稱呼它?有誰能向我澄清這件事嗎?
UPDATE: 這afirmation是書SCJA Sun認證Java助理學習指南真正的 - 考試CX-310-019從認證考試題號6
採取(麥格勞 - 希爾,2009年,第5章)
我沒有看到真正的問題。 – 2013-02-16 00:42:18
http://en.wikipedia.org/wiki/Scope_%28computer_science%29 – 2013-02-16 00:44:15
http://www.cs.berkeley.edu/~jrs/4/lec/08 – user1428716 2013-02-16 00:46:24