outer5.java
来自「JAVA编程思想源代码 值得一下 很难找的」· Java 代码 · 共 32 行
JAVA
32 行
package chapter6;
public class Outer5 {
public static void main(String[] args) {
OuterX outer = new OuterX();
outer.print();
}
}
class OuterX {
private int index = 100;
class Inner {
private int index = 50;
void print() {
int index = 30;
System.out.println("in the method index = " + index); // 30
System.out.println("in the inner class index = " + this.index); // 50
System.out.println("in the outer class index = "
+ OuterX.this.index); // 100
}
}
void print() {
Inner inner = new Inner();// 得到内部类的引用
inner.print();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?