aspose file tools*
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
Author

Inner classes

Doit
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
Wanderer
Sheriff

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:
<code><pre>
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();
}
}
</pre></code>


"I'm not back." - Bill Harding, Twister
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Inner classes