aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Constructors are not inhertied - True Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Constructors are not inhertied - True" Watch "Constructors are not inhertied - True" New topic
Author

Constructors are not inhertied - True

Arulkumar Gopalan
Ranch Hand

Joined: Oct 13, 2003
Posts: 104

Constructors are not inhertied - True

But while creating object for a sub class, why is it automatically invokes super class constructors?


Anbudan & Mahalo,<br />Arul<br /> <br />-Not a sun certified Java professional :-)
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Because other members of the superclass are inherited. For example, any non-private data members are inherited and those members may be initialized in the constructors of the parent class. If the parent class constructor wasn't executed, those members would now be uninitialized, which is definitely not what we want.


SCJP Tipline, etc.
mrudul joshi
Ranch Hand

Joined: Nov 12, 2003
Posts: 54
Even I got the same problem.
finally, are the constructors inherited or they are not?
Thanks
Cathy Song
Ranch Hand

Joined: Aug 24, 2003
Posts: 270
Constructors are NOT inherited.
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
Hi Mrudul. No, constructors are Never inherited.
The constructors of classes B, C and D invoke the superclass constructor A().

[ November 19, 2003: Message edited by: Marlene Miller ]
sherry cuenco
Greenhorn

Joined: May 07, 2003
Posts: 24
Constructors are not inherited but...
if the super constructors are automatically invoked by the system, everytime a new instance of a class is created, it's like saying the super constructors are "inherited" by the constructor.

Result:
Invoked super constructor A
Invoked super constructor B
Invoked super constructor C
Test

So, the way I view it, the super constructors of the constructor are "inherited" by the constructor because they are automatically invoked by the system everytime an instance is created.
Please correct me on this. Thanks!
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391

Does class B "inherit" constructor A()?
Does class B "inherit" constructor A(int)?
A() is automatically invoked, A(int) is not.
B has access to both constructors.
[ November 21, 2003: Message edited by: Marlene Miller ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Constructors are not inhertied - True
 
Similar Threads
Main method inheritance
MATH and null bug me.....
Marcus mock 3 No.43
Reg Constructors
Why Boolean Objects are not mainted in cache?