Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Call to super constructor from Derived class constructor

 
Sibendu Dey
Greenhorn
Posts: 20
Java Oracle Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have a doubt.

Whenever the derived class constructors calls the super class constructor , is it actually creating a new instance of super class along with the instance of derived class?

Thank you.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It might be helpful to realise that the constructor doesn't actually create the object. It initialises an object that has been created (e.g. by a new statement).
 
Shawn Nicolson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following this train of thought.

If a parent object is not created when a child object is instantiated, against what object instance are the parents non static methods executed?


 
Paul Clapham
Sheriff
Posts: 21576
33
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Against the object.

There's only one object involved when you create an object. For example if you create a String object there's only one object. Just because String extends Object it doesn't mean there's a String object and an Object object. There's only one object, and that object is an instance of String as well as an instance of Object.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic