This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Ranch Office and the fly likes Inner Class 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 » This Site » Ranch Office
Bookmark "Inner Class" Watch "Inner Class" New topic
Author

Inner Class

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi,
I found this code in the Getting in Touch with your Inner Class
tutorial on this site, but I think you cannot create an inner class object as specified in the code
Inner i = o.new Inner();
Shouldn't it be
Outer.Inner i = o.new Inner();
??
thankx
dre

class Outer
{
private int size ;
private String thoughts = "My outer thoughts";
class Inner
{
String innerThoughts = "My inner thoughts";
void doStuff()
{
// inner object has its own "this"
System.out.println( innerThoughts );
// and it also has a kind of "outer this"
// even for private data of outer class
System.out.println(thoughts);
}
}
}
class TestMe
{
public static void main( String args[] )
{
// instantiate me, the outer object
Outer o = new Outer();
// Inner i = new Inner();
// NO! Can't instantiate Inner by itself!
Inner i = o.new Inner();
// now I have my special inner object
i.doStuff();
// OK to call methods on inner object
}
}
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
You're right - good catch. I'm moving this to the "Java Ranch" topic to be sure Paul sees it, as he's the one who could fix the error. (Hi Paul!) Thanks.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inner Class
 
Similar Threads
innerclasses
Question about the "Getting in Touch with your Inner Class" campfire tutorial
Question about "Getting in Touch with your Inner Class "
Instantiating Inner Classes
outer class from inner class