• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

super();

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This code would call all of the parents constructors or methods. Is that correct?
 
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 (coderanch, protected etc)).
super.someParentMethod();
Hope that helps.
/ James
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic