标签:java class nbsp tin pac AMM sys new 概念
package JavaBasicReview; public class JavaGrammer { public static void main(String[] args) { //创建外部类,外部类在内部类之前创建,内部类创建后会获取外部类对象的引用 Outer outer = new Outer(); outer.getInner(); System.out.println("====it‘s Inner======"); //创建成员内部类,使用内部类之前,外部类会自动创建 Outer.Inner inner = new Outer().new Inner(); inner.show(); } } class Outer { private int age = 16; public Outer() { System.out.println("Outer created!"); } //成员内部类 class Inner { private int age = 17; public Inner() { System.out.println("Inner created!"); } void show() { System.out.println("Outer‘s age:" + Outer.this.age); System.out.println("Inner‘s age:" + this.age); } } void getInner() { Inner inner = new Inner(); System.out.println("Outer‘s age:" + this.age); System.out.println("Inner‘s age:" + inner.age); } }
Outer created!
Inner created!
Outer‘s age:16
Inner‘s age:17
====it‘s Inner======
Outer created!
Inner created!
Outer‘s age:16
Inner‘s age:17
标签:java class nbsp tin pac AMM sys new 概念
原文地址:https://www.cnblogs.com/bajiaotai/p/12887743.html