看板 java 關於我們 聯絡資訊
想問大家 這個code哪裡錯了 public class a1 { public static void main(String args[]) { double a; area C1 =new area(); a=C1.area1(5, 6); } class area{ public double area1(double a, double b){ return a+b; } } } 這個area C1 =new area(); 這裡 Eclipse一直出現錯誤 這不就是呼叫area建構子 為什一直有錯 No enclosing instance of type a1 is accessible. Must qualify the allocation with an enclosing instance of type a1 (e.g. x.new A() where x is an instance of a1). 這個是什麼意思 可以請高手幫忙解答嗎 小弟是java初學者 -- 木瓜種子居然也能種成盆栽 夠神奇吧 http://www.newsancai.com/b5/health/9-pedia/75624-.html -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.230.250.239 ※ 文章網址: https://www.ptt.cc/bbs/java/M.1490079946.A.169.html
ssccg: area是a1的inner class(也就是area的物件一定要關聯到一個 03/21 15:32
ssccg: a1物件),所以要先new一個a1的物件,才能用它new area 03/21 15:34
adrianshum: 要不把area 搬到外面,要不改成static nested class 03/21 18:57
xw: 因為是inner class的關係無誤,另外class習慣上大寫開頭 03/22 21:33
xw: 還有就是繼承應該是在講另一個故事... 03/22 21:34
eieio: static class area 就會過了吧 03/23 14:19