• Post Reply Bookmark Topic Watch Topic
  • New Topic

Explicit constructor invocation  RSS feed

 
Donna Jane
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is it necessary to use an explicit constructor invocation?



from oracle web site.

Why not just go right to



And just use the above code and skip the parameterless constructor?
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do it but by providing extra constructor you are providing more flexibility to the user to choose..
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not necessary to write the explicit constructor invocation. But if you don't the compiler will implicity add “super();” which might not be what you want. If the superclass doesn't have an accessible no‑arguments constructor the code won't even compile.
What you are saying by that explicit call is, “You must provide a location but we can imfer top if you miss it out.” Top left is of course (0, 0).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!