• Post Reply Bookmark Topic Watch Topic
  • New Topic

Inheritance and Constructors...  RSS feed

 
Naveen Mishra
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

There is a doubt about inheritance and constructors
In the simplest words , any thing which is not private in a super class is inherited to the sub class.
What happens to constructors ?
As I read they are not inherited .

How this is working... any inside look on the matter, please

Thanks
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No constructors are not inherited. Constructors are used to initialize the instance variables in a class definition when an instance is created. The nice thing about the inheritance mechanism is that when a subclass is created, a constructor from the superclass is always called. So we do not have to redo all of the work done in the superclass to initialize its variables, we can simply invoke the appropriate superclass constructor and have it initliaze the variables that the superclass gives to the subclass, and the subclass can take care of initializing the variables it adds to what the superclass gives it.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!