This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes overriding constructor of inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "overriding constructor of inner class" Watch "overriding constructor of inner class" New topic
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
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

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: 18541
    
    8

"Gz Portland", please check your private messages regarding an important administrative matter.

Thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: overriding constructor of inner class
 
Similar Threads
Clarification n Innerclass
Inner Class
what wrong with my code?
Doubt in innerclass
Global data and external classes