靜態(tài)內(nèi)部類實(shí)例
http://img1.sycdn.imooc.com//539e948a0001a71007630511.jpg
http://img1.sycdn.imooc.com//539e94a500014f0101930052.jpg
http://img1.sycdn.imooc.com//539e948a0001a71007630511.jpg
http://img1.sycdn.imooc.com//539e94a500014f0101930052.jpg
2015-08-25
舉報(bào)
2015-12-15
//外部類
public class HelloWorld {
? ??
? ? // 外部類中的靜態(tài)變量score
? ? private static int score = 84;
? ??
? ? // 創(chuàng)建靜態(tài)內(nèi)部類
public static ? class SInner {
? ? ? ? // 內(nèi)部類中的變量score
? ? ? ? int score = 91;
? ? ? ??
public void show() {
System.out.println("訪問外部類中的score:" + HalloWard.score ? ? ? ? ?);
System.out.println("訪問內(nèi)部類中的score:" + score);
}
}
// 測(cè)試靜態(tài)內(nèi)部類
public static void main(String[] args) {
// 直接創(chuàng)建內(nèi)部類的對(duì)象
? ? ? ??
? ? ? ? SInner si=new SInner();
? ? ? ? // 調(diào)用show方法
si.show();
}
}