[問題] 請問this.getClass().getName()的用法

看板java作者 ( )時間16年前 (2009/11/22 23:06), 編輯推噓2(202)
留言4則, 2人參與, 最新討論串1/1
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

11/22 23:14, , 1F
關鍵字 static
11/22 23:14, 1F

11/22 23:40, , 2F
原來是static和non-static的問題 不是getClass().getName()
11/22 23:40, 2F

11/22 23:42, , 3F
改成建構式就沒問題了 tks !!
11/22 23:42, 3F

11/23 00:09, , 4F
錯誤訊息不就告訴你了 ==
11/23 00:09, 4F
文章代碼(AID): #1B2LDvZZ (java)