Win a copy of Learn Java with Math: Using Fun Projects and Games this week in the Beginning Java forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Question about "Getting in Touch with your Inner Class "

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I'm new to this site and Java and apologise if this isn't the correct forum to post this.
In the article "Getting in Touch with your Inner Class ", I refer to a line of code that the author says can be used to "instantiate both the outer class and inner class at the same time":
Inner i = new Outer().new Inner();
My question is :
Does this really work ? I've tried this and get a compile error:
TestMe.java:33: Class Inner not found in type declaration.
Inner i = new Outer().new Inner();
^
1 error
Is this related to the version of Java I'm using ?
Thanks in advance.
Ravi..
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should be Outer.Inner i = new Outer().new Inner();
 
Sheriff
Posts: 9099
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on where you instantiate it.

[ April 23, 2003: Message edited by: Marilyn de Queiroz ]
 
Marilyn de Queiroz
Sheriff
Posts: 9099
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, Ravi, your display name does not conform to the JavaRanch Naming Policy. Although that does not matter in this forum, if you post in the other forums, you will be requested to change it. Thanks.
 
Ravi Anamalay
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marilyn,
I've changed my display name - I should show up as "Ravi Varman" and not "Ravi A". Sorry about that - I should have read the naming policy more carefully.
Secondly, thanks for clearing up the question I had about instantiating inner classes.
 
Marilyn de Queiroz
Sheriff
Posts: 9099
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Ravi, and you're welcome.
 
And will you succeed? Yes you will indeed! (98 and 3/4 % guaranteed) - Seuss. tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!