為什么定義一個(gè)新的newScore,內(nèi)部類方法中newScore=score+10不可以
public?class?Hello?{ ????private?String?name?=?"愛慕課"; ????//?外部類中的show方法 ????public?void?show()?{ ????????//?定義方法內(nèi)部類 ????????class?MInner?{ ????????????int?score?=?83; ????????????int?newScore=0; ????????????public?int?getScore()?{ ????????????????newScore=score+10; ????????????} ????????} ????????//?創(chuàng)建方法內(nèi)部類的對(duì)象 ????????MInner?i=new?MInner(); ????????i.getScore(); ????????System.out.println("姓名:"?+?name?+?"\n加分后的成績:"?+?newScore); ????}
2019-01-26
你的方法內(nèi)部類中定義的方法是int型的要一個(gè)返回值
2019-01-26
你的內(nèi)部類定義在外部類的方法中
2018-11-23
首先你的newScore是在方法內(nèi)部類中定義的,并不能在方法外部使用。因?yàn)榉椒▋?nèi)部定義的變量為局部變量,其作用域?yàn)閺拇俗兞慷x開始至包含該變量的塊。
你的內(nèi)部類的方法并沒有返回。
2018-11-06
newScore這個(gè)變量沒有聲明