| Author |
Constructors.
|
Ritu Kapoor
Ranch Hand
Joined: Oct 03, 2004
Posts: 101
|
|
|
Query: What is the use of declaring a constructor as protected, when we know that the constructors are not inherited.
|
 |
Pradeep bhatt
Ranch Hand
Joined: Feb 27, 2002
Posts: 8876
|
|
|
Protected constuctors can be called by subclasses and also classes within the same package.
|
Groovy
|
 |
agrah upadhyay
Ranch Hand
Joined: Sep 01, 2005
Posts: 579
|
|
Although constructors are not inherited yet they aare called implicitly by run time system or explicitly by U
|
<i>--Agrah Upadhyay--</i><br />Final Year B.Tech SCJP,SCWCD,SCBCD <br /> <br /><b>Now since the real test for any choice is having to make the same choice again,knowing full well what it might cost.</b>-Oracle
|
 |
Akhilesh Trivedi
Ranch Hand
Joined: Jun 22, 2005
Posts: 1493
|
|
This seems tricky. Guess, if I have a "private" constructor and inherit a subclass from it. Now, when I would instantiate a sub-class sub-class constructor will be called which will in-turn call super class constructor, but is that accessible??? Shows error. Good... thank you all.
|
Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
|
 |
A Kumar
Ranch Hand
Joined: Jul 04, 2004
Posts: 973
|
|
Hi, As akhil had mentioned in his post... We cannot instantiate the class with only private constructor.. Such class object can be created only in that same class... So in the event of inheriting this class...you cannot instantiate an object of the sub class...since the base class constructor is not visible to the sub class.. If it is protected ....it is visible in any other class withing this package and any other class that extends this base class... So we can instantiate an object of this sub class.. But if we want to instantiate an object of the base class elsewhere ...in a different package..it behaves as a private scope...whether you are extending that class or not... In case you are extending...you can cannot create directly the base class.. instance...but you can create instance of the extended class.. in this extended class..  [ October 05, 2005: Message edited by: A Kumar ]
|
 |
Ritu Kapoor
Ranch Hand
Joined: Oct 03, 2004
Posts: 101
|
|
|
Thanks to kumar & Akhil.
|
 |
 |
|
|
subject: Constructors.
|
|
|