• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

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

 
Greenhorn
Posts: 6
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.








 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hmm...you may be right.
 
Jeff Cortez
Greenhorn
Posts: 6
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cool...gaining some Java traction. Thanks Fred!
 
Marshal
Posts: 79670
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Campbell!
 
pie. tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic