What is function overloading code example
Example 1: c++ function overload
#include <iostream>
using namespace std;
int function1(int var1){
}
int function1(int var1,int var2){
}
int function1(int var1,string var3){
}
int main(){
cout << "Hello World" << endl;
function1(4);
function1(3,-90);
function1(34,"it works");
return 0;
}
Example 2: method overloading
public class Sum {
public int sum(int x, int y)
{
return (x + y);
}
public int sum(int x, int y, int z)
{
return (x + y + z);
}
public double sum(double x, double y)
{
return (x + y);
}
public static void main(String args[])
{
Sum s = new Sum();
System.out.println(s.sum(10, 20));
System.out.println(s.sum(10, 20, 30));
System.out.println(s.sum(10.5, 20.5));
}
}
Example 3: method overloading
Method overloading is providing
two separate methods in a class
with the same name but different arguments,
while the method return type
may or may not be different, which
allows us to reuse the same method name.
In my framework==
I use implicit wait in Selenium. Implicit wait
is an example of overloading. In Implicit wait
we use different time stamps such as SECONDS, MINUTES, HOURS etc.,
A class having multiple methods with
same name but different parameters
is called Method Overloading
Example 4: what is method overloading
Method overloading is providing
two separate methods in a class
with the same name but different arguments,
while the method return type
may or may not be different, which
allows us to reuse the same method name.
In my framework==
I use implicit wait in Selenium. Implicit wait
is an example of overloading. In Implicit wait
we use different time stamps such as SECONDS, MINUTES, HOURS etc.,
A class having multiple methods with
same name but different parameters
is called Method Overloading
Example 5: method overloading
Method overloading is providing two separate methods in a class
with the same name but different arguments, while the method return type
may or may not be different, which allows us to reuse the same method name.