151220InnerClassDemo

来源:互联网 发布:国外优秀搜索引擎 知乎 编辑:程序博客网 时间:2024/06/15 05:53
package java151220;


class InnerClassDemo {
public static void main(String[] args) {
// Outer outer = new Outer();
// outer.method();


// Outer.Inner inner=new Outer().new Inner();
// inner.Function();
// new Outer.Inner().Function();
Outer.Inner.Function();
Outer.method();
}


}


/*
 * 内部类的访问规则: 内部类可以直接访问外部类中的成员,包括私有
 * 
 * 
 */
class Outer {


private int x = 3;
private static int y = 3;


// void method() {
// // System.out.println(x);
// // Inner inner=new Inner();
// // inner.Function();
// Inner.Function();
// }


static class Inner {


// int x=4;
static void Function() {


// int x=6;
System.out.println("Inner :" + y);
}
}

class Inner2{
void show(){
System.out.println("innner2 show");
}
}


public static void method() {
// Inner.Function();
// new Inner2().show(); No enclosing instance of type Outer is accessible. Must qualify the allocation with an enclosing instance of type Outer (e.g. x.new A() where x is an instance of Outer).
}

}
0 0
原创粉丝点击