Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Jeff Cortez
Greenhorn
Posts: 6
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12145
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeff Cortez
Greenhorn
Posts: 6
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12145
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmm...you may be right.
 
Jeff Cortez
Greenhorn
Posts: 6
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool...gaining some Java traction. Thanks Fred!
 
Campbell Ritchie
Sheriff
Pie
Posts: 49382
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree; the name of the class is Outer.Inner, not Inner, unless you are already inside the Outer class.
 
Jeff Cortez
Greenhorn
Posts: 6
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Campbell!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic