FileDocCategorySizeDatePackage
InnerClass1.javaAPI DocExample509Sat Nov 25 12:55:42 GMT 2000None

InnerClass1.java

/** Demonstrate simple inner class. A named inner class
 * is used to show that it can access non-local variables
 * in the enclosing object.
 */
public class InnerClass1 {
	String msg = "Hello";

	void doWork() {
		Inner i = new Inner();
		i.doTheWork();
		msg = "Goodbye";
		i.doTheWork();
	}

	public static void main(String[] av) {
		InnerClass1 p = new InnerClass1();
		p.doWork();
	}

	class Inner {
		public void doTheWork() {
			// print member of enclosing class
			System.out.println(msg);
		}
	}
}