wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes instantiating an inner member class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "instantiating an inner member class" Watch "instantiating an inner member class" New topic
Author

instantiating an inner member class

Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
This is not a question.
Various ways to instantiate a non-static member class.

[ August 13, 2003: Message edited by: Marlene Miller ]
venu gopal
Ranch Hand

Joined: Nov 21, 2000
Posts: 40
Hi Marlene this is a great posting, thank you. It covers everything required for inner class instantiation. Could you please add for static and anonymous also?
[ August 13, 2003: Message edited by: venu gopal ]
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
Thank you Venu for reading my posting. Thank you for your response. That's a good suggestion. I will try to do something for those other classes, now that I know it might be helpful.
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
Various ways to instantiate a static member class.

[ August 13, 2003: Message edited by: Marlene Miller ]
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
Some anonymous class instantiations.

Note: A is not final
[ August 14, 2003: Message edited by: Marlene Miller ]
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
A thought about instantiating anonymous subclasses of nested classes.
I think it is safe to say,
If C is a top-level, static member, non-static member or local class,
and C is not final, then where ever this is valid syntax to instantiate the class,
new C()
new Outer.C()
outerRef.new C()
new Outer().new C()
this is also valid syntax to instantiate an anonymous class.
new C() { <body of anon class> }
new Outer.C() { <body of anon class> }
outerRef.new C() { <body of anon class> }
new Outer().new C() { <body of anon class> }
[ August 14, 2003: Message edited by: Marlene Miller ]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Could you please add for static and anonymous also?
Why no local?
Looking good, Marlene. Thanks for posting these.


"I'm not back." - Bill Harding, Twister
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: instantiating an inner member class