📜  java 外部类 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:14.808000             🧑  作者: Mango

代码示例1
class OuterClass {
  int x = 10;

  class InnerClass {
    int y = 5;
  }
}

public class Main {
  public static void main(String[] args) {
    OuterClass myOuter = new OuterClass();
    //OuterClass.InnerClass myInner = new OuterClass.InnerClass();
    OuterClass.InnerClass myInner = myOuter.new InnerClass();
    System.out.println(myInner.y + myOuter.x);
  }
}