| Author |
overriding constructor of inner class
|
Laiq Ahmed
Ranch Hand
Joined: Jan 04, 2010
Posts: 44
|
|
Kindly review the following and tell me why I cant override the constructor of inner class?
|
 |
Neha Daga
Ranch Hand
Joined: Oct 30, 2009
Posts: 504
|
|
|
as far as I know constructors can never be overridden.
|
SCJP 1.6 96%
|
 |
Laiq Ahmed
Ranch Hand
Joined: Jan 04, 2010
Posts: 44
|
|
Neha Daga wrote:as far as I know constructors can never be overridden.
Thanks Neha. You are right.
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
|
As Neha said, constructors cannot be overridden. Inner classes can define their own constructors but not anonymous inner classes, they cannot have a constructor. If you want to perform some initialization operation in the anonymous inner class, you can use instance initializer block...
|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
|
 |
Graciela Zaffarana
Greenhorn
Joined: Jan 09, 2010
Posts: 17
|
|
Hi there ...
I am in the middle of inner classes myself; I took a look at the code submitted; with some minor changes as shown below, the code compiled.
Best,
GZPortland
|
 |
Venu Chakravorty
Ranch Hand
Joined: Aug 19, 2009
Posts: 46
|
|
Hi, Gz Portland
I think that's a case of constructor overloading.
|
 |
Graciela Zaffarana
Greenhorn
Joined: Jan 09, 2010
Posts: 17
|
|
Yes, yes; I am afraid that I realized after I hit the submit button. Was surprised that none was jumping the gun. My apologies.
And, yes, yes. Rule of thumb: constructors can be overloaded but not overriden. Well... better now than at exam time!
Thank-you,
GZPortland -- very greenhorn
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
"Gz Portland", please check your private messages regarding an important administrative matter.
Thank you.
|
 |
 |
|
|
subject: overriding constructor of inner class
|
|
|