2. INTRODUCTION
• If a class of a Java program has a plural number of methods, and all of
them have the same name but different parameters (with a change in type
or number of arguments), and programmers can use them to perform a
similar form of functions, then it is known as method overloading.
• If programmers wants to perform one operation, having the same name,
the method increases the readability of the program.
• Method Overloading is applied in a program when objects are required to
perform similar tasks but different input parameters. Every time an object
calls a method, Java matches up to the method name first and then the
number and type of parameters to decide what definitions to execute.
3. • This process of assigning multiple tasks to the same method is known
as Polymorphism. There are different ways to overload a method in Java.
They are:
• Based on the number of parameters: In this case, the entire overloading
concept depends on the number of parameters that are placed within the
parenthesis of the method.
• Based on the data type of the parameter: With the arrangement of data type,
within the parameter, overloading of the method can take place.
• Based on the sequence of data types in parameters: The method
overloading also depends on the ordering of data types of parameters
within the method.
6. Why method overloading in java is not possible by
changing the return type of method is changed?
• In Java, method overloading is not possible by changing the return type of
the method because there may arise some ambiguity. Let's see how
ambiguity may occur:
7. • The above program will generate a compile-time error.
• Here, Java cannot determine which sum() method to call and hence creates an error if you want
to overload like this by using the return type. Overloading methods offer no specific benefit to the
JVM, but it is useful to the program to have several ways do the same things but with different
parameters.
10. PROGRAM TO DEMONSTRATE METHOD OVERLOADING BASED
ON THE SEQUENCE OF DATA TYPE IN THE PARAMETERS
11. ADVANTAGES
• It is used to perform a task efficiently with smartness in programming.
• It increases the readability of the program.
• The Method overloading allows methods that perform proximately related
functions to be accessed using a common name with slight variation in
argument number or types.
• They can also be implemented on constructors allowing different ways to
initialize objects of a class.
12. DISADVANTAGES
• Not very easy for the beginner to opt this programming technique and go
with it.
• It requires more significant effort spent on designing the architecture (i.e.,
the arguments' type and number) to up front, at least if programmers' want
to avoid massive code from rewriting.