Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
is not correct. The super class constructor is called.[ Also the super class constructor is called only when you explicitly call it by using the
method super().So by default constructors are not inherited whereas methods are. ]
Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Originally posted by Kavita Ghia:
Hi,
I have edited the the above code to extend Base class.
To be very specific my question is How are constructors and methods inherited withe various access modifiers?
Kavita.
Originally posted by Kavita Ghia:
Hi Sandeep,
I did follow your explanation but got one point to confirm.
Does it means that if your Derived class has a default constructor still it will go up the heirarchy(ONLY to the IMMEDIATE super class)and call the super class constructor implicitly and then its own constructor the way Paul's(OUR BARTENDER) example shows the output.And accordingly the derived class constructors will behave.
Therefore the following implies:
IF SUPER CLASS CONSTRUCTORS ARE:
1.PRIVATE => cannot instantiate subclass
2.PROTECTED=> cannot instantiate subclass
3.DEFAULT=>can instantiate subclass
4.PUBLIC=>can instantiate subclass
(Ofcourse the same will apply to the super class as well.)
Thanks,
Kavita.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |