阅前声明: http://blog.csdn.net/heimaoxiaozi/archive/2007/01/19/1487884.aspx
/****************** Exercise 7 ******************
* Modify Exercise 6 so that two of the
* overloaded methods have two arguments (of two
* different types), but in reversed order
* relative to each other. Verify that this
* works.
***********************************************/
class Dog2 {
public void bark(int i, double f) {
System.out.println("int, double bark");
}
public void bark(double f, int i) {
System.out.println("double, int bark");
}
}
public class E07_SwappedArguments {
public static void main(String args[]) {
Dog2 dog = new Dog2();
dog.bark(1, 2.2);
dog.bark(2.2, 1);
}
}
//+M java E07_SwappedArguments
**This exercise emphasizes that it’s not only the type of arguments that are used to distinguish an overloaded method, but also the order of the arguments. In the above example, the two versions of bark( ) are unique.