Java Reference
In-Depth Information
If the return type of the non- abstract method is not a subtype of the return type of
any of the other inherited methods, a compile-time unchecked warning occurs
unless suppressed by the SuppressWarnings annotation (§ 9.6.3.5 ) .
A compile-time error occurs if the return type of the non- abstract method is not
return-type-substitutable (§ 8.4.5 ) for each of the other inherited methods.
A compile-time error occurs if the inherited method that is not abstract has a
throws clause that conflicts (§ 8.4.6 ) with that of any other of the inherited meth-
ods.
• If all the inherited methods are abstract , then the class is necessarily an abstract class
and is considered to inherit all the abstract methods.
One of the inherited methods must be return-type-substitutable for every other in-
herited method; otherwise, a compile-time error occurs. (The throws clauses do not
cause errors in this case.)
There might be several paths by which the same method declaration might be inherited
from an interface. This fact causes no difficulty and never, of itself, results in a compile-
time error.
8.4.9. Overloading
If two methods of a class (whether both declared in the same class, or both inherited by a
class, or one declared and one inherited) have the same name but signatures that are not
override-equivalent, then the method name is said to be overloaded .
This fact causes no difficulty and never of itself results in a compile-time error. There is no
required relationship between the return types or between the throws clauses of two methods
with the same name, unless their signatures are override-equivalent.
When a method is invoked (§ 15.12 ), the number of actual arguments (and any explicit type
arguments) and the compile-time types of the arguments are used, at compile time, to de-
termine the signature of the method that will be invoked (§ 15.12.2 ) . If the method that is
to be invoked is an instance method, the actual method to be invoked will be determined at
run time, using dynamic method lookup (§ 15.12.4 ) .
Example 8.4.9-1. Overloading
Click here to view code image
class Point {
float x, y;
void move(int dx, int dy) { x += dx; y += dy; }
Search WWH ::




Custom Search