不能使用在方法之內,
方法內也不能再定義方法
類別內,static不可呼叫non-static,只可呼叫static,
non-static則都可,
因static不需要被建立就可執行,
亦即static成員中根本沒有隱含的this參考指標指向物件,
但non-static卻未被建立,必須先new出來才可用
public class Test {
  void a() {
    b(); //正確
    d(); //正確
  }
  void b() {}
  static void c() {
    b(); //錯誤,不可直接呼叫b()
    d(); //正確,可直接呼叫d()
  }
  static void d(){
    new Test().b(); //正確,可直接呼叫b()
  }  
}
0 意見 :
張貼留言