• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why call to This() and Super() should be in first line of constructor  RSS feed

 
Mahesh Karehonna
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why call to This() and Super() should be in first line of constructor
 
Mansukhdeep Thind
Ranch Hand
Posts: 1163
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the ranch Mahesh. There are no keywords This() and Super() in Java language.

And it's either call to super() OR this(), not super() AND this().
 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because super() and this() must run before any other code in the constructor. This is because a constructor is the starting point or the initial building block for your object and so must be executed before anything else. Moreover, a call to super() itself calls the constructor of the Parent Class.

cheers
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mahesh Pk wrote:Why call to This() and Super() should be in first line of constructor


Because the Java language spec requires that the parent class be fully initialized before the current class starts executing its constructor.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!