-
Book Overview & Buying
-
Table Of Contents
OCA: Oracle Certified Associate Java SE 8 Programmer I Study Guide: Exam 1Z0-808
By :
Now that you are familiar with the rules for declaring methods, it is time to look at creating methods with the same name in the same class. Method overloading occurs when there are different method signatures with the same name but different type parameters.
We've been calling overloaded methods for a while. System.out.println and StringBuilder's append methods provide many overloaded versions so you can pass just about anything to them without having to think about it. In both of these examples, the only change was the type of the parameter. Overloading also allows different numbers of parameters.
Everything other than the method name can vary for overloading methods. This means there can be different access modifiers, specifiers (like static), return types, and exception lists.
These are all valid overloaded methods:
public void fly(int numMiles) { }
public void fly(short numFeet) { }
public boolean fly() { return false; }
void fly(int numMiles, short...
Change the font size
Change margin width
Change background colour