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.
/** * Get String presentation for this Thing object. * @return human readable summary of fields in Thing object. */ @Override public String toString() { return desc + " " + quantity + " " + losses; }
![]() |
and suggestions to improve this page to Roedy Green : | ||
| Canadian Mind Products | |||
| mindprod.com IP:[65.110.21.43] | |||
| Your face IP:[38.103.63.18] | 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 | ||