1Overloading mean same method name and different parameter,
2it can happen in same class. it's a feature that
3allows us to have more than one method with same name.
4
5Example: sort method of Arrays class
6Arrays.sort(int[] arr)
7Arrays.sort(String[] arr)
8....
9Method overloading improves the reusability and readability.
10and it's easy to remember
11(one method name instead of remembering multiple method names)
1Method overloading is providing
2two separate methods in a class
3with the same name but different arguments,
4while the method return type
5may or may not be different, which
6allows us to reuse the same method name.
7In my framework==
8I use implicit wait in Selenium. Implicit wait
9is an example of overloading. In Implicit wait
10we use different time stamps such as SECONDS, MINUTES, HOURS etc.,
11A class having multiple methods with
12same name but different parameters
13is called Method Overloading
1//https://www.geeksforgeeks.org/overloading-in-java/
2// Java program to demonstrate working of method
3// overloading in Java.
4
5public class Sum {
6
7 // Overloaded sum(). This sum takes two int parameters
8 public int sum(int x, int y)
9 {
10 return (x + y);
11 }
12
13 // Overloaded sum(). This sum takes three int parameters
14 public int sum(int x, int y, int z)
15 {
16 return (x + y + z);
17 }
18
19 // Overloaded sum(). This sum takes two double parameters
20 public double sum(double x, double y)
21 {
22 return (x + y);
23 }
24
25 // Driver code
26 public static void main(String args[])
27 {
28 Sum s = new Sum();
29 System.out.println(s.sum(10, 20));
30 System.out.println(s.sum(10, 20, 30));
31 System.out.println(s.sum(10.5, 20.5));
32 }
33}
1/https://www.geeksforgeeks.org/overloading-in-java/
2// Java program to demonstrate working of method
3// overloading in Java.
4
5public class Sum {
6
7 // Overloaded sum(). This sum takes two int parameters
8 public int sum(int x, int y)
9 {
10 return (x + y);
11 }
12
13 // Overloaded sum(). This sum takes three int parameters
14 public int sum(int x, int y, int z)
15 {
16 return (x + y + z);
17 }
18
19 // Overloaded sum(). This sum takes two double parameters
20 public double sum(double x, double y)
21 {
22 return (x + y);
23 }
24
25 // Driver code
26 public static void main(String args[])
27 {
28 Sum s = new Sum();
29 System.out.println(s.sum(10, 20));
30 System.out.println(s.sum(10, 20, 30));
31 System.out.println(s.sum(10.5, 20.5));
32 }
33}
340
35program for method overloading in java
1Method overloading is providing two separate methods in a class
2with the same name but different arguments, while the method return type
3may or may not be different, which allows us to reuse the same method name.