/Users/lyon/j4p/src/bookExamples/ch12Nested/Outer.java

1    package bookExamples.ch12Nested; 
2     
3    /* 
4        This example shows 
5        how to create a nested class. 
6        The Outer class is class called "Outer". 
7        The Inner class is class called "Inner". 
8        The Outer class contains the Inner class. 
9        Inner classes are useful for defining temporary 
10       reference data types. 
11   */ 
12    
13   class Outer { 
14       Inner i = new Inner(); 
15    
16       public static void main(String args[]) { 
17           Outer o = new Outer(); 
18           o.i.print(); 
19       } 
20    
21       class Inner { 
22           void print() { 
23               System.out.println("hello from Inner class!"); 
24           } 
25       } 
26   } 
27    
28   //class DontWork { 
29   //  Inner i = new Inner(); 
30   //}