public?class?Staticlearn?{
????static?int?score1?=?66;????????????????//定義靜態(tài)變量
????static?int?score2?=?99;?
????public?static?int?sum(){???????????????//定義靜態(tài)方法
????????int?sum?=?score1?+?score2;
????????return?sum;?//返回值
????}
????public?int?show(){
????????//System.out.println(sum);??普通成員方法需要會報錯
????????int?show?=?sum();
????????System.out.println(score1);??????????????//普通成員方法可以直接訪問靜態(tài)變量或非靜態(tài)變量
????????return?show;
????}
????public?static?void?main(String[]?args){
????????Staticlearn?object?=?new?Staticlearn();???//創(chuàng)建類的對象
????????int?allScore?=?object.show();?????????//靜態(tài)方法訪問普通成員方法???
????????System.out.println(allScore);
????}
}我梳理了一份序列,求大佬幫我看看是不是對的~static靜態(tài)方法??????? -靜態(tài)變量????? (直接訪問)??????? -非靜態(tài)變量?? (創(chuàng)建類的對象訪問)??????? -靜態(tài)方法????? (直接調(diào)用)??????? -非靜態(tài)方法?? (創(chuàng)建類的對象訪問)普通成員方法??????? -靜態(tài)變量????????(直接訪問)??????? -非靜態(tài)變量?????(直接訪問)??????? -靜態(tài)方法????????(通過對象調(diào)用)??????? -非靜態(tài)方法????(直接訪問)
添加回答
舉報
0/150
提交
取消