1. Home
  2. Computing & Technology
  3. Java
photo of Paul Leahy
Paul's Java Blog

By Paul Leahy, About.com Guide to Java

Java Term of the Week: Super

Saturday January 17, 2009

This week's Java term is the super keyword. It enables a subclass to call the methods and fields of its superclass. It's important to note that it is not an instance of the superclass object. It's simply a way to tell the compiler which methods or fields to reference. The effect of using a super.methodname statement is the same as if the subclass is calling one of its own methods.

For example, if an Employee class extends a Person class:

public class Employee extends Person{

  public Employee()
  {
    //reference the superclass constructor
    super();
  }

  public String getName()
  {
    //reference superclass behaviors
    return super.getFirstName() + " " + super.getLastName();
  }
}

The super keyword can be used to reference the constructer of the Person class or any of the behaviors or fields that it has access to (e.g., getFirstName() and getLastName()).

Comments

No comments yet. Leave a Comment

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

Discuss
Community Forum
Explore Java
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Java

©2009 About.com, a part of The New York Times Company.

All rights reserved.