[問題] extends inner class

看板java作者 (痕天)時間17年前 (2009/06/10 16:43), 編輯推噓1(101)
留言2則, 1人參與, 最新討論串1/3 (看更多)
public class Circle { class Point { public int x = 5, y = 2; public Point(int x, int y) { this.x = x; this.y = y; } public String toString() { return x + ", " + y; } } } public class Test extends Circle.Point { public Test() { System.out.println(toString()); } } compile的時候出現這個錯誤 Test.java:2: an enclosing instance that contains Circle.Point is required public Test() { ^ 1 error 請問是無法繼承inner class嗎? 新手JAVA首PO 請多指教 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.120.210.186

06/10 22:11, , 1F
Test()的第一行加上 new Circle().super(1, 2);
06/10 22:11, 1F

06/10 22:12, , 2F
non-static inner class需要一個outer class的instance
06/10 22:12, 2F
文章代碼(AID): #1ABt8T9f (java)
討論串 (同標題文章)
文章代碼(AID): #1ABt8T9f (java)