• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

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: 13081
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: 13081
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: 76817
366
  • 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!
 
snakes are really good at eating slugs. And you wouldn't think it, but so are tiny ads:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic