Java Reference
In-Depth Information
m 2 is public , protected , or declared with default access in the same package as C ,
or
m 1 overrides a method m 3 ( m 3 distinct from m 1 , m 3 distinct from m 2 ), such that
m 3 overrides m 2 .
Moreover, if m 1 is not abstract , then m 1 is said to implement any and all declarations of ab-
stract methods that it overrides.
The signature of an overriding method may differ from the overridden one if a formal
parameter in one of the methods has a raw type, while the corresponding parameter in
the other has a parameterized type.
The rules allow the signature of the overriding method to differ from the overridden
one, to accommodate migration of pre-existing code to take advantage of generics.
See § 8.4.2 for further analysis.
It is a compile-time error if an instance method overrides a static method.
In this respect, overriding of methods differs from hiding of fields (§ 8.3 ), for it is per-
missible for an instance variable to hide a static variable.
An overridden method can be accessed by using a method invocation expression (§ 15.12 )
that contains the keyword super .
A qualified name or a cast to a superclass type is not effective in attempting to access
an overridden method; in this respect, overriding of methods differs from hiding of fields
15.12.4.4 ) .
The presence or absence of the strictfp modifier has absolutely no effect on the rules for
overriding methods and implementing abstract methods. For example, it is permitted for a
method that is not FP-strict to override an FP-strict method and it is permitted for an FP-
strict method to override a method that is not FP-strict.
Example 8.4.8.1-1. Overriding
Click here to view code image
class Point {
int x = 0, y = 0;
void move(int dx, int dy) { x += dx; y += dy; }
}
class SlowPoint extends Point {
int xLimit, yLimit;
void move(int dx, int dy) {
Search WWH ::




Custom Search