what is function overloading | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

what is function overloading

explain with program

17th Sep 2016, 7:21 PM
Ankit Panwar
Ankit Panwar - avatar
6 Answers
+ 2
Function overloading is defining several functions with the same name but different parameters. When the function is called, the right one is picked based on the number and data type of the parameters. public class Program { public static void overFun(int n) { System.out.println("The parameter is an int!"); } public static void overFun(double n) { System.out.println("The parameter is a double!"); } public static void main(String[] args) { overFun(42); overFun(42.0); } }
17th Sep 2016, 7:36 PM
Zen
Zen - avatar
+ 2
What? But I did explain in my language...
17th Sep 2016, 7:40 PM
Zen
Zen - avatar
+ 1
Function overloading also known as compile time polymorphism is when you have more than one function with the same signature but with different args or same agrs but different data types.
17th Sep 2016, 7:42 PM
Ousmane Diaw
+ 1
In the simple language method overloading is you use one then more method in same method name but different parameters, signature, and return type under the same class.
18th Sep 2016, 7:30 AM
balram sao
balram sao - avatar
0
how it works..plz xplain in ur language .dont use copy cut paste
17th Sep 2016, 7:39 PM
Ankit Panwar
Ankit Panwar - avatar
0
int add( int a); int add( int a, int b); int add( float a, float b); int add( int a,int b, int c); all these are different method signatures with the same name but with different types of arguments. It is called as method overloading. based on number of arguments and type of arguments that particular method will be invoked. ex: add(1); // calls add(int a) method. add(1.2f, 2.4f); // calls add( float a, float b) method. add(1,2);// calls add( int a,int b) method
18th Sep 2016, 2:49 AM
Teja Naraharisetti
Teja Naraharisetti - avatar