Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Extended JFrame, use 'super'?

 
Adam Till
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
For consistency, if you have a class that extends JFrame do you use e.g. super.whatEver(); or just whatEver()? Personaly I like it but not sure what the general way is, if there is one.
Thanks
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a constructor, you can call the superclass constructor using super() syntax.If you don't insert the call to super() as the first line in the constructor, the compiler will insert an implicit no-argument call to the superclass constructor. It is considered good practice to always put in the super() call regardless.
For method calls, you use super.methodName() syntax.If you would omit the "super." prefix, the foobar() method would be recursively calling itself -- probably leading into an endless loop and an eventual death in a stack overflow.
- Peter
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic