aspose file tools*
The moose likes Beginning Java and the fly likes Question about the Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Question about the "Getting in Touch with your Inner Class" campfire tutorial" Watch "Question about the "Getting in Touch with your Inner Class" campfire tutorial" New topic
Author

Question about the "Getting in Touch with your Inner Class" campfire tutorial

Jeff Cortez
Greenhorn

Joined: Jan 22, 2011
Posts: 6

Hi. I'm trying to understand inner and nested classes and have started by reading the "Getting in Touch with your Inner Class" campfire tutorial:

http://www.javaranch.com/campfire/StoryInner.jsp

I compiled the classes Outer and TestMe and ran TestMe with the correct output.
Immediately under that example, the tutorial goes on to say:

You can also instantiate both the outer class and inner class at the same time:

So, in class TestMe I commented out these two lines:


And inserted this line instead:

However, now class TestMe does not compile.
I then changed the statement to this:

The class TestMe again compiles and runs with the correct output.
Am I misunderstanding something in the campfire tale, or is this statement in the tutorial a bug? That is, Inner i needs to be changed to Outer.Inner i in the code snippet below.

You can also instantiate both the outer class and inner class at the same time:

Thanks.








fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11499
    
  16

Instead of saying "the class does not compile", please tell us the exact text of what it does say. Having that text makes it MUCH easier for folks to help you.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Jeff Cortez
Greenhorn

Joined: Jan 22, 2011
Posts: 6

Hi. In a file TestMe.java I have two class declarations TestMe and Outer. I commented out these two lines in TestMe:


And inserted this from the tutorial:


When I try to compile the file, I get this compiler error message:

TestMe.java:12: cannot find symbol
symbol : class Inner
location: class TestMe
Inner i = new Outer().new Inner();
^
1 error


My question is whether this statement in the campfire tutorial:


should instead be changed to this:


Thanks.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11499
    
  16

hmm...you may be right.
Jeff Cortez
Greenhorn

Joined: Jan 22, 2011
Posts: 6

Cool...gaining some Java traction. Thanks Fred!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40059
    
  28
Agree; the name of the class is Outer.Inner, not Inner, unless you are already inside the Outer class.
Jeff Cortez
Greenhorn

Joined: Jan 22, 2011
Posts: 6

Thank you Campbell!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question about the "Getting in Touch with your Inner Class" campfire tutorial