next up previous contents
Next: Inner and Nested Classes: Up: Java Notes Previous: Inner and Nested Classes:

Inner and Nested Classes: Member 1

/**
 *  This code is edited from the book:
 *    Winder, R and Roberts, G (1998):
 *	  Developing Java Software 
 *	  John Wiley & Sons.
 *  It is copyright (c) 1997 Russel Winder 
 *	and Graham Roberts.
 */

class l1Memb1{//Class5
    private class Member{
        //private instance variables of the 
        //enclosing class object can be accessed
        public void test(){
            i += 10;
            System.out.println(i);
            System.out.println(s);
        }
    }

    //creates a Member class object which
    //has access to the private state of
    //the object it is called for.
    public void test(){
        Member n = new Member();
        n.test();
    }

    public static void main(String[] args){
        l1Memb1 c5 = new l1Memb1();
        c5.test();
    }

    private int i = 10;
    private String s = "hello";
}
/******** sample compilation & run *******
# javac l1Memb1.java 
# java l1Memb1      
20
hello
# 
******************************************/



Ananda Amatya
9/15/1999