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
1Method 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.
2
3Method overriding means defining a method in a child class that is already defined in the parent class with the same method signature, same name, arguments, and return type
1Method Overloading:
2Access modifier can be same or different,
3Return-Type can be same or different,
4Parameters MUST be different, Method name MUST be same,
5any method can be overloaded
6
7Method Overriding:
8After a method is inherited it is possible to change
9the implantation of the method in the child class.
10This concept is called overriding.
11Method name, Parameter, and Return-Type MUST be same
12access modifier MUST be same or more visible,
13MUST happen in the sub class,
14ONLY the instance methods can be overridden
15@Override annotation MUST be applicable.
16Static and Constructor cannot be override.
17We can use the @Override annotation before the method
18to declare the overriding.
19EXAMPLE: get method WebDriver driver = new ChromeDriver();
20driver.get("URL") ==> opens the url from chrome
21
1Overriding means same method name and same parameter,
2occur in different class that has inheritance relationship.
3we use method overriding to implement specific functionality to the method.
4
5Example: get method
6WebDriver driver = new ChromeDriver();
7driver.get("URL") ==> opens the url from chrome
8
9WebDriver driver = new FireFoxDriver();
10driver.get("URL") ==> opens the url from Firefox
11
12we can only override instance methods and method override
13takes place in sub class.
14instance method that we are going to override cannot be private and final
1Overriding means same method name and same parameter,
2occur in different class that has
3inheritance relationship.
4we use method overriding to implement
5specific functionality to the method.
6
7Examples are get and navigate methods
8of different drivers in Selenium .
9
10Example: get method
11WebDriver driver = new ChromeDriver();
12driver.get("URL") ==> opens the url from chrome
13
14WebDriver driver = new FireFoxDriver();
15driver.get("URL") ==> opens the url from Firefox
16
17we can only override instance methods and method override
18takes place in sub class.
19instance method that we are going to override cannot be private and final
20Example: get method
21WebDriver driver = new ChromeDriver();
22driver.get("URL") ==> opens the url from chrome
23
24WebDriver driver = new FireFoxDriver();
25driver.get("URL") ==> opens the url from Firefox
26
27we can only override instance methods and method override
28takes place in sub class.
29instance method that we are going to
30override cannot be private and final
1Overriding means same method name and same parameter,
2occur in different class that has
3inheritance relationship.
4we use method overriding to implement
5specific functionality to the method.