慕萊塢1282154
2017-08-16 15:04:39
package com.one;public class NightTest {?? ??? ?static int score =89;?? ?static int score1 = 87;?? ?public? static int sum(){?? ??? ?return score+score1;?? ??? ??? ??? ??? ?}?? ?public static void main(String[] args) {?? ??? ??? ??? ??? ??? ?System.out.println("總分為:"+NightTest.sum);?? ?}}
4 回答
已采納

抗震性能
TA貢獻(xiàn)4條經(jīng)驗 獲得超3個贊
用類名調(diào)用方法 :
類名.方法名();
System.out.println("總分為:"+NightTest.sum());


_Leslie
TA貢獻(xiàn)9條經(jīng)驗 獲得超2個贊
sum應(yīng)該為sum()。
而且方法和變量名不推薦用靜態(tài)吖
可以這樣:?int score =89;
? ? ? ? ? ? ? ? ? int score1 = 87;
? ? ? ? ? ? ? ? ? public ? int sum()
?在main中 ?NightTest nightTest =new NightTest();
? ? ? ? ? ? ? ? ? 然后調(diào)用 ?nightTest.sum()方法
添加回答
舉報
0/150
提交
取消