// File: TestLocal2.java (Module 10) // // Author: Rahul Simha // Created: Nov 2, 1998 // // Creating an instance of a non-static // member class. class A { // Instance data in A int y; // Constructor for A. public A (int y) { this.y = y; } // Instance member class: class B { int x; // Data. public B (int i) { // Constructor. x = i; } public void print () // A method. { System.out.println ("B: x=" + x + ", y=" + y); } } } public class TestLocal2 { public static void main (String[] argv) { // Create an instance of A first. A a = new A (1); // Now create an "associated" instance of B. // Note the strange syntax! A.B b = a.new B (2); b.print(); // Prints "B: x=2, y=1" } }