1. Technology
Send to a Friend via Email

Your suggestion is on its way!

An email with a link to:

http://java.about.com/od/s/g/super.htm

was emailed to:

Thanks for sharing About.com with others!

Super

By

Woman using laptop on patio
Jetta Productions/Blend Images/Getty Images
Definition:

The super keyword enables a subclass to call the methods and fields of its superclass. It is not an instance of the superclass object but a way to tell the compiler which methods or fields to reference. The effect is the same as if the subclass is calling one of its own methods.

Examples:

Consider a subclass Employee that extends its superclass Person:

 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()).

Glossary:

# A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

©2014 About.com. All rights reserved.