Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Constructors are not inhertied - True

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even I got the same problem.
finally, are the constructors inherited or they are not?
Thanks
 
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Constructors are NOT inherited.
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Just the other day, I was thinking ... about this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic