@Override : Java Glossary
home punctuation words local find no local find frame, full screen Google search web for topic jump to footer translate with Babelfish 2008-02-17 by Roedy Green ©1996-2008 Canadian Mind Products
Go to : punctuation 0-9 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 (all)
@Override
To override means to provide a replacement method in a new class for one in the superclass. The superclass too will use your new method in place of its own when dealing with objects of your type, though it will continue to use its own method for objects purely of its own type. Be careful. The rules for figuring out exactly which version of a method get invoked are baroque.

Your overridden method must have the same return type, though with JDK 1.5+, you have the option of covariance where your overriding method can be a subclass or the root method’ return type.

When overriding a method, be careful to exactly match the method signature, or you will end up just adding another method, rather than replacing the superclass version. You are permitted to widen the scope however, e.g. make your new method public where the original was default.

Using @Override

There is no override keyword to warn the compiler your method is intended to override a method in the base class. However, since JDK 1.6, (and partially in JDK 1.5), there is an @Override annotation. @Override serves as documentation for the reader and a double check in the compiler. The compiler will warn you if your method is not overriding properly, usually because the two method names are not spelled exactly the same way. Note it is @Override with capital O and double r, not @overide. Don’t confuse the @Override annotation with the unofficial @override Javadoc command. Here is how you would use the @Override annotation to indicate that a method is overriding another in the base class.
/**
 * Get String presentation for this Thing object.
 * @return human readable summary of fields in Thing object.
 */
@Override
public String toString()
  {
  return desc + " " + quantity + " " + losses;
  }

CMP_homejump to top
CMP logo
feedback Please email your feedback for publication, errors, omissions, broken/redirected link reports
and suggestions to improve this page to Roedy Green : feedback email
made with CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[65.110.21.43]
Your face IP:[38.103.63.16] The information on this page is for non-military use only.
You are visitor number 11. Military use includes use by defence contractors.
You can get a fresh copy of this page from: or possibly from your local J: drive (Java virtual drive/Mindprod website mirror)
http://mindprod.com/jgloss/atoverride.html J:\mindprod\jgloss\atoverride.html