File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes inner classes example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "inner classes example" Watch "inner classes example" New topic

inner classes example

Mathew Lee
Ranch Hand

Joined: Jun 08, 2009
Posts: 238
>>>But what happens if there is no existence of this for the class Outer. To make sense of the rather odd syntax provided for this try to think of the keyword new as used in the above example as belonging to the current insistence of this.

Thus you could change the line that creates the instance of this to read

Inner i = Inner();
Thus if you need to create an instance of Inner from a static method or somewhere else where there is no this object you can use new as a method belonging to the outer class

class Outer{
public class Inner{}

class another{
public void amethod(){
Outer.Inner i = new Outer().new Inner();

I was reading above lines from link

did not understand it clearly.

Any ideas, resources,sample code,links, highly appreciated. thanks in advance.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46337
Thinking in Java by Bruce Eckel.
I agree. Here's the link:
subject: inner classes example
It's not a secret anymore!