static 只能放在類別層級
package variableScope;//相當於folder/subfolder路徑,必須放在程式碼第一行
public class variableScope {
int i =1; //instance,全域變數
static int j=3;//static
public static void kkk(int k)
{
// variableScope obj2 = new variableScope();
int l=1;//local
//System.out.println("j is "+j);
//System.out.println(i);//error, must declare a object
// System.out.println("k is"+k);
}
public static void main(String[] args) {
//variableScope obj = new variableScope();
// System.out.println(i);//error, must declare object
System.out.println(variableScope.j);
System.out.println("no . class"+j);
// System.out.println(k);//error,can not find local variable k
// System.out.println(l);//as above
// kkk(3)
}
}
沒有留言:
張貼留言