靜態(tài)內(nèi)部類(lèi)能不能訪(fǎng)問(wèn)非靜態(tài)外部類(lèi)啊
????public class p{
????????private int a=2;
public static class o{
? ? ? ?int b=3;
public ?void show(){
System.out.println(a);
System.out.println(b);................
????public class p{
????????private int a=2;
public static class o{
? ? ? ?int b=3;
public ?void show(){
System.out.println(a);
System.out.println(b);................
2015-11-13
舉報(bào)
2015-11-14
但是我卻得到了報(bào)錯(cuò)呢:
//外部類(lèi)
public class HelloWorld1 {
??
? // 外部類(lèi)中的靜態(tài)變量score
? private static int score = 84;
? private ?int score2 = 8;
? // 創(chuàng)建靜態(tài)內(nèi)部類(lèi)
public ? static ?class SInner {
? ? ? // 內(nèi)部類(lèi)中的變量score
? ? ? int score = 91;
? ? ??
public void show() {
System.out.println("訪(fǎng)問(wèn)外部類(lèi)中的score:" + ?HelloWorld1.score );
? ? ? ? ? ? System.out.println("訪(fǎng)問(wèn)外部類(lèi)中的score1:" + ?new HelloWorld1.score2 );
System.out.println("訪(fǎng)問(wèn)內(nèi)部類(lèi)中的score:" + ?score);
}
}
// 測(cè)試靜態(tài)內(nèi)部類(lèi)
public static void main(String[] args) {
// 直接創(chuàng)建內(nèi)部類(lèi)的對(duì)象
? ? ? SInner si= new SInner();
? ?// HelloWorld1 d = new HelloWorld1();
? ? ?// SInner so= d.new SInner();
? ? ? // 調(diào)用show方法
si.show();
}
}
2015-11-13
知道了