Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

super();

 
Kevin Knowles
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This code would call all of the parents constructors or methods. Is that correct?
 
James Clinton
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
super() will call the conctructor of you extending class. Also if used it must be the first line in a contructor method.
For example:

// PARENT CLASS

// CHILD CLASS


Calling super is only neccessay if you have code in the constructor that needs initialising.
Else you can happy invoke its methods (assuming they are visible (public, protected etc)).
super.someParentMethod();
Hope that helps.
/ James
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code would call all of the parents constructors or methods. Is that correct?
No. super() would only invode the superclass constructor that takes no arguments.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic