aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes declare inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "declare inner class" Watch "declare inner class" New topic
Author

declare inner class

Tony Xu
Greenhorn

Joined: Sep 27, 2001
Posts: 27
I know there are lots of threads about inner class. I checked some, still have question about the foll question from RHE.
Construction of an inner class may require an instance of the outer class. //True
Explation given in book:
Constructing an instance of a static inner class does not need an instance of the enclosing object, but all non-static inner classes do require such a reference, and that reference must be available to the new operation. The reference to the enclosing object is commonly implied as this, which is why it is commonly not explicit. These points make E true.
Hence, can I say this:
Construction of an inner class requires an instance of the outer class. //False, since static inner class does not need that.
BTW, do I need to know anything about how to declare an instance of inner class which is in a method block?
Please clarify. Thanks.
Elizabeth Lester
Ranch Hand

Joined: Aug 14, 2001
Posts: 129
Hi Tony,
Originally posted by Tony Xu:
can I say this:
Construction of an inner class requires an instance of the outer class. //False, since static inner class does not need that.?

I think the statement "Construction of an inner class requires an instance of the outer class" is vague and therefore arguable:
The statements
"Construction of an inner class ALWAYS requires an instance of the outer class"

"Construction of a static inner class requires an instance of the outer class"
are false (for the reason you mention above).
The statements:
"Construction of an inner class MAY require an instance of the outer class"
"Construction of a MEMBER or LOCAL inner class requires an instance of the outer class"
are true.
Originally posted by Tony Xu:
BTW, do I need to know anything about how to declare an instance of inner class which is in a method block

Yes. There are 4 kinds of inner classes, all of which are discussed in RHE chapter 6: static, member, local, and anonymous. You should know how to declare them all, and what variables in the enclosing class and/or method they have access to.
I hope that helps!
--liz
------------------
Elizabeth Lester
SCJP Dreamin'
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Hi Elizabeth.

Construction of a MEMBER or LOCAL inner class requires an instance of the outer class"

Why an instance of the outer class is needed if the member nested class is static or it was defined within a static method?


SCJP2. Please Indent your code using UBB Code
Elizabeth Lester
Ranch Hand

Joined: Aug 14, 2001
Posts: 129
Hi Jose,
Originally posted by Jose Botella:
Construction of a MEMBER or LOCAL inner class requires an instance of the outer class"
Why an instance of the outer class is needed if the member nested class is static or it was defined within a static method?

Yes, you are right. My statement was too general. The outer class instance is not needed if the inner class is static or defined in a static method.
Thank you for your clarification.
--liz

[This message has been edited by Elizabeth Lester (edited September 30, 2001).]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel
 
subject: declare inner class
 
Similar Threads
Two questions about mock exam
Anonymous Inner class
inner class static or no?
question about static inner classes
Inner class... how and why ?