Your overridden method must have the same return type, though with Java version 1.5 or later, you have the option of covariance where your overriding method can be a subclass or the root method’s 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.
There is no override keyword to warn the compiler your method is intended to override a method in the base class. However, since Java version 1.5 or later, 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 @Overridewith 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. Note it is not inside the Javadoc comment!
/** * Get String presentation for this Thing object. * @return human readable summary of fields in Thing object. */ @Override public String toString() { return desc + " " + quantity + " " + losses; }
This page is posted |
http://mindprod.com/jgloss/atoverride.html | |
Optional Replicator mirror
|
J:\mindprod\jgloss\atoverride.html | |
Please read the feedback from other visitors,
or send your own feedback about the site. Contact Roedy. Please feel free to link to this page without explicit permission. | ||
Canadian
Mind
Products
IP:[65.110.21.43] Your face IP:[18.97.14.81] |
| |
Feedback |
You are visitor number | |