➧Method Overloading in Java :
When Methods of the same name are used more than once in their Java Source Code, there are Concepts of Method Overloading. When you are making a big software, the methods of the same name are used many times. The names of so many Methods can be remembered in small programs. But remembering the names of the Methods in the big software is a difficult task for programs. Therefore, programmers use Concept of Method Overloading.
In the Concepts of "Methods Overloading", all Methods of the same Methods perform similar Tasks are written in the same way. A method can not be used the second time as before. If this is done, then "method is already define in a class" error will be generated.
For example, for calculating 2 integer numbers, the Parameters of Integer Types will be passed and when calling Call Methods, the value of the Integer type will be passed. And if the value of float type is to be Sum then float Data-type will be passed in Parameters within the Methods and while calling Methods, the value of the float type will be passed, similarly in the case of String.
Now it comes out that how will the compiler identify methods like this? What time do you have to execute the method? So the answer is that the number of parameters passed in the Methods will be different, and if the Parameters do not separate, then their data-types will be different. When these methods are called, then the type of value from which value will be passed there will be stores in the same methods, which will have a Data-type or the number of values that will be passed at the time of the call, the number of the number of methods will be stored in Parameters.
For Example :
Source Code :
OUTPUT : Value of P is : 5
Sum of P & Q is : 17.4
Multiplication of P, Q & R is : 1242.882Sum of P & Q is : 17.4
In this program, three types of int types of Same Name have been created. Within these methods, the number of parameters and parameters of Parameters has been given differently, so that in the Runtime, the compiler should know which value to be executed for the method.
Read Also :
Like this post, If you find Topic useful in this post, so share it with your friends and colleagues on Facebook, Twitter, whatsapp and Google Plus.
Thank You !
Note – For More Core & Advance Java Concepts , Tutorials And Programs Are Available in www.kptechsolution.com
0 Comments