外部方法調用內部變量或方法
//可先創建內部類的對象,然后通過內部類的對象來訪問其成員變量和方法。 //請問以下代碼為什么不對?位置不對?謝謝回答。 public?class?A{ public?class?B{ int?s?=?21; } public?void?method(){ System.out.println(""+b.s); } public?static?void?main(String[]?args){ A?a?=?new?A(); B?b?=?a.new?B(); a.method(); } }
2015-03-10
正確代碼
2015-03-09
你第8行代碼中的b是個什么變量,也沒有聲明啊?