Java Reference
In-Depth Information
As you can see, ovlDemo( ) is overloaded four times. The first version takes no parameters,
the second takes one integer parameter, the third takes two integer parameters, and the
fourth takes two double parameters. Notice that the first two versions of ovlDemo( ) return
void , and the second two return a value. This is perfectly valid, but as explained, overload-
ing is not affected one way or the other by the return type of a method. Thus, attempting to
use the following two versions of ovlDemo( ) will cause an error:
As the comments suggest, the difference in their return types is insufficient for the purposes
of overloading.
As you will recall from Chapter 2 , Java provides certain automatic type conversions.
These conversions also apply to parameters of overloaded methods. For example, consider
the following:
Search WWH ::




Custom Search