GeeCON Prague 2014*
The moose likes Ranch Office and the fly likes Question about Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » This Site » Ranch Office
Bookmark "Question about "Getting in Touch with your Inner Class "" Watch "Question about "Getting in Touch with your Inner Class "" New topic
Author

Question about "Getting in Touch with your Inner Class "

Ravi Anamalay
Ranch Hand

Joined: Apr 15, 2003
Posts: 38
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..


with kind regards,<br />Ravi
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
It should be Outer.Inner i = new Outer().new Inner();


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10
It depends on where you instantiate it.

[ April 23, 2003: Message edited by: Marilyn de Queiroz ]

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10
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

Joined: Apr 15, 2003
Posts: 38
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

Joined: Jul 22, 2000
Posts: 9046
    
  10
Thanks, Ravi, and you're welcome.
 
 
subject: Question about "Getting in Touch with your Inner Class "