Meaningless Drivel is fun!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inner classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inner classes" Watch "Inner classes" New topic

Inner classes

Ranch Hand

Joined: Aug 03, 2000
Posts: 169
Can some one please prrove with small examples that,
non-static inner classes have reference of outer class reference assosiated with them while static inner classes and local inner
classes does not have.
- Thanks
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
But local classes do have outer instances associated with them, as long as the local class isn't defined in a static context:
class Outer {

private String field = "field which is part of an Outer instance";

public void method() {
class Local {
public void message() {
System.out.println("See, I can access a " + Outer.this.field);
new Local().message();

public static void main(String[] args) {
new Outer().method();

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: Inner classes
jQuery in Action, 3rd edition