wood burning stoves*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "inner classes example" Watch "inner classes example" New topic
Author

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 = this.new 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
http://www.jchq.net/certkey/0401certkey.htm

did not understand it clearly.


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

Joined: Oct 13, 2005
Posts: 36453
    
  15
Thinking in Java by Bruce Eckel.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: inner classes example
 
Similar Threads
Nested Classes
Inner classes
inner classes
How to Contruct an Inner Class Instance
K&B doubt: Inner class name from static context of outer class