我有一個叫ChristopherRobin
(HundredAcreWoodsCharacter
的子類)的類,其中有一個叫做FindTail()
的方法。非靜態方法不能從靜態上下文中引用?
在另一類Eeyore
(子類HundredAcreWoodsCharacter
也)中,我想嘗試使用ChristopherRobin
中的方法FindTail()
。我不知道如何做到這一點。我試圖
if (ChristopherRobin.hasTail())
但給我的錯誤:
non-static method hasTail() cannot be referenced from a static context
如果有人可以幫助將是巨大的,謝謝。
此外,如果值得一提的是,這是在GridWorld
(來自AP計算機科學案例研究)完成的。 HundredAcreWoodsCharacter
是Critter
的一個子類。
你調用非靜態方法*在類*,無法完成的事情。您需要先創建一個ChristopherRobin對象,然後調用該對象的方法。 – 2013-04-06 15:58:40
你應該發佈你的代碼爲ChristopherRobin和HundredAcreWoods。 – Thorn 2013-04-06 16:20:19
Google發現了數百個解釋此錯誤消息的項目。你甚至試圖谷歌它? – Vitaly 2013-04-06 16:31:32