The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2000



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Accessing Inner classes (from Thinking In Java)

Posted by Sridhar Visvanath on November 17, 2000 at 1:25 AM

I have the following lines taken from Thinking in Java by Bruce Eckel ,Chapter 8 Interfaces and Inner Classes .

There Bruce says

"IF you want to make an object of the inner class anywhere except from within a non-static method of the outer class , you must specify the type of that object as OuterClassName.InnerClassName ".

that is to say ,

if you are accessing an Inner class "Inner" from a instance method of "Outer" then

Inner in = ...
will be enough

whereas if you are accessing from a class method / static method
of " Outer " / from any other classes then type should be
Outer.Inner in = ...

however , when I tried to access the inner class from static method of the enclosing "Outer" class by saying

Inner c = new Outer().new Inner();

It works fine

This is not to point out the fault , I wanna know whether it works fine in all compilers and environments

I did it on Windows environ , with Kawa IDE (the IDE does not matter however) on Jdk 1.2

Sridhar Visvanath


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us