• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Constructors are not inhertied - True

 
Ranch Hand
Posts: 104
  • 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?
 
Ranch Hand
Posts: 3271
  • 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.
 
Ranch Hand
Posts: 54
  • 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
 
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Constructors are NOT inherited.
 
Ranch Hand
Posts: 1392
  • 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 ]
 
Greenhorn
Posts: 24
  • 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
  • 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 ]
 
That new kid is a freak. Show him this tiny ad:
Enterprise-grade Excel API for Java
https://products.aspose.com/cells/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!