0
what is function overloading
explain with program
6 odpowiedzi
+ 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);
}
}
+ 2
What? But I did explain in my language...
+ 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.
+ 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.
0
how it works..plz xplain in ur language .dont use copy cut paste
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