Java内部类入门示例

public class test {
	public static void main(String[] args) {
		OuterClass out = new OuterClass();
		OuterClass.InnerClass1 inner1 = new OuterClass().new InnerClass1();
		OuterClass.InnerClass2 inner2 = out.new InnerClass2();
		out.method();
		inner1.method();
		inner2.method();
	}
}

class OuterClass {
	int outerData;
	void method() {
		System.out.println("Outer Class.");
	}
	class InnerClass1 {
		int data;
		void method() {
			System.out.println("Inner Class 1.");
		}
	}
	class InnerClass2 {
		int data;
		void method() {
			System.out.println("Inner Class 2.");
		}
	}
}


原文链接: http://blog.csdn.net/poechant/article/details/6941254

你可能感兴趣的:(Java内部类入门示例)