看板 java 關於我們 聯絡資訊
public class a{ public static void main( String arg[] ) { System.out.println( this.getClass().getName() ); } } -------- 以上是全部的程式碼 以下是compile後的結果 a.java:4: non-static variable this cannot be referenced from a static context System.out.println( this.getClass().getName() ); ^ 1 error 請問一下這樣子的寫法哪裡出錯了呢 tks !! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.168.93.193
PsMonkey:關鍵字 static 11/22 23:14
hijje:原來是static和non-static的問題 不是getClass().getName() 11/22 23:40
hijje:改成建構式就沒問題了 tks !! 11/22 23:42
PsMonkey:錯誤訊息不就告訴你了 == 11/23 00:09