Data Structures, Algorithms, & Applications in Java
Chapter 1, Exercise 5
- (a)
-
The signature of the method invocation agrees with that of
the
abc method of Program 1.2.
Therefore, the abc method of
Program 1.2 is invoked.
- (b)
-
The signature of the method invocation agrees with that of
the
abc method of Program 1.3.
Therefore, the abc method of
Program 1.3 is invoked.
- (c)
-
The signature of the method invocation does not agree
with that of either of the
abc methods.
However, Java will do an implicit type conversion from
int to
float but not from
float to
int.
By performing this type conversion, the signature of the invocation
can be made to agree with that of
the abc method of Program 1.3.
Therefore, the abc method of
Program 1.3 is invoked.
- (d)
-
The actual parameters are of type
double.
Java will not do an implicit type conversion from a type with higher
precision to one with lower precision.
In particular, data of type
double are not implicitly converted
to float
or
int. Therefore, the signature of the invocation
cannot be matched via implicit type coversion to that
of either of the
abc methods and a compiler error results.
- (e)
-
This also causes a compiler error.
The reason is the same as for the compiler error for (d).
The actual parameter 3.0 is of type
double and cannot
be implicitly converted to
float
or
int.