30 likes | 189 Views
Unit-1 Introduction to Java. Overloading. Overloading. Overloading is a mechanism in which we can use many methods having the same function name but can pass different number of parameters or different types of parameters.
E N D
Unit-1 Introduction to Java Overloading
Overloading • Overloading is a mechanism in which we can use many methods having the same function name but can pass different number of parameters or different types of parameters. • If you call max with int parameters, the max method that expects int parameters will be invoked; if you call max with double parameters, the max method that expects double parameters will be invoked.
Can you invoke the max method with an int value and a double value, such as max(2, 2.5)? If so, which of the max methods is invoked? The answer to the first question is yes. The answer to the second is that the max method for finding the maximum of two double values is invoked. The argument value 2 is automatically converted into a double value and passed to this method.