• Post Reply Bookmark Topic Watch Topic
  • New Topic

help in super constructor call  RSS feed

 
Amarjeet Anand
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In scjp 6 study guide, chapter 2, its written that every constructor calls its super class constructor. And we know, constructors are called to create an object.
Does it mean that if I am creating an object of a class, I am actually creating objects of all its super class???
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. The constructors all apply to the same single object.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amarjeet Anand wrote: . . . And we know, constructors are called to create an object. . . .
That isn't quite true. If you go through the Java Language Specification (=JLS), it says the constructor is called after the object has been created and before the instance creation expression returns. What the constructor does is convert the default values for all the fields to “real” values. If you go through that section, which, unlike some parts of the JLS, you can probably understand, it says object and instance. It never says objects or instances.
 
Amarjeet Anand
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your response. I got it.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome . I have corrected a spelling error in my previous post: say sobjects is now says objects.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!