This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Constructors are not inhertied - True

 
Arulkumar Gopalan
Ranch Hand
Posts: 104
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Constructors are not inhertied - True

But while creating object for a sub class, why is it automatically invokes super class constructors?
 
Corey McGlone
Ranch Hand
Posts: 3271
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
mrudul joshi
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even I got the same problem.
finally, are the constructors inherited or they are not?
Thanks
 
Cathy Song
Ranch Hand
Posts: 270
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Constructors are NOT inherited.
 
Marlene Miller
Ranch Hand
Posts: 1392
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1392
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic