java2從頭開學(xué)(13)
package 數(shù)據(jù)類型;
//作用域
class Scope {
?public static void main(String args[]){
??int x;
??
??x = 10;
??if(x == 10){
???int y = 20;
???
???System.out.println("x and y: " + x + " " + y);
???x = y * 2;
??}
??// y = 100;//Error! y not known here
??
??// x is still known here.
??System.out.println("x is " + x);
?}
}
posted on 2008-04-11 14:35 dripstone 閱讀(198) 評(píng)論(0) 編輯 收藏