Wednesday, November 16, 2011

Tuesday, November 1, 2011

static nested class and non-static nested (inner) class

http://stackoverflow.com/questions/70324/java-inner-class-and-static-nested-class

-----------------------------------static nested---------------------------------------

package pizza;
public class Rhino {

    ...

    public static class Goat {
        ...
    }
}
 
### 

Rhino.Goat goat = new Rhino.Goat(); 
 
###
NOTE: 
A non-static nested class (or 'inner class') has full access to the members of the class within which it is nested.
    
-----------------------------------non-static nested (inner)---------------------------------------

package pizza;
public class Rhino {

    public class Goat {
        ...
    }

    private void jerry() {
        Goat g = new Goat();
    }
}
 
### 
Rhino rhino = new Rhino();
Rhino.Goat goat = rhino.new Goat();
 
###
A static nested class does not have a reference to a nesting instance, so a static nested class cannot invoke non-static methods or access non-static fields of an instance of the class within which it is nested. 

http://stackoverflow.com/questions/1353309/java-static-vs-non-static-inner-class

http://www.brpreiss.com/books/opus5/html/page601.html