aspose file tools*
The moose likes Beginning Java and the fly likes Accessing inner class -- error? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Accessing inner class -- error?" Watch "Accessing inner class -- error?" New topic
Author

Accessing inner class -- error?

Steve Edwards
Greenhorn

Joined: Jan 25, 2005
Posts: 2
What seems to be an error in "Getting in Touch with your Inner Class" (Campfire Stories): You can also instantiate both the outer class and inner class at the same time:


Recreating the whole example in Eclipse, it doesn't pass the syntax checker. According to JCHQ, the syntax is

This compiles and runs for me. Excuse an uppity beginner, but what do you think?
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
In the article, in the code just above the statement you pointed out, they have the variable with the correct type Outer.Inner. So you are correct. Probably a typo.

Thanks, I'll try to get someone to fix it.
[ January 25, 2005: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Steve Edwards
Greenhorn

Joined: Jan 25, 2005
Posts: 2
Barry,

Thanks, you answered my question. Yes, I see the line you are talking about where Outer o is instantiated first, and then Outer.Inner i from there. The typo's a little more unfortunate since it comes right after the comment:

// Inner i = new Inner();
// NO! Can't instantiate Inner by itself!

I hope my picking comes across in good humor. Actually, the article is the most helpful explanation I've come across and helped a lot. Thank you!

Steve
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Another possiblity is that there is an import statement at the top of the source. Something like:

If so, this will make it possible to use the syntax as given:


Layne


Java API Documentation
The Java Tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing inner class -- error?