> For the complete documentation index, see [llms.txt](https://gyansetu-selenium.gitbook.io/selenium-testing/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gyansetu-selenium.gitbook.io/selenium-testing/method-overloading.md).

# METHOD OVERLOADING

&#x20;**Definition:** Developing multiple methods with the same name, but variations in the arguments list. Variations in the arguments list can be:-

&#x20;**1)** Number of arguments.

&#x20;**2)** Types of arguments.&#x20;

**3)** Position/order of arguments Whenever we want to perform the common operation or task with the variations in the inputs, we should choose Method Overloading.

&#x20;**Example:** If you want to write a program to perform addition of 2 numbers and 3 numbers, then we should develop 2 methods with 1 to receive 2 inputs and 1 more to receive 3 inputs. Instead of developing these methods with different names, we can develop with same name “add”.

&#x20;**Example:** If you are developing an application and you are giving 2 options for the user name and password and another with the mobile numbers and password. Here also we should develop 2 methods with the variation in the inputs instead of developing this methods with different name the operation is common, we can develop it with the same name.

> &#x20;**Note:** Through Method Overloading:-

1\) We can achieve consistency in the method names, which are developed for common purpose.

&#x20;2\) It is easy to remember method name. 3) We can achieve efficiency in the program readability.&#x20;

4\) We can achieve compile-time Polymorphism through Overloading.&#x20;

5\) While overloading, method name should be same with the variations in the arguments list, other parts of method does not matter, i.e., Return type, modifiers, access level can be different.&#x20;

6\) We can overload static and non-static methods.&#x20;

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTfNKnN7FirW1DQ4BZU%2F-LTfOpdLQbDz0IcXQ9Yp%2Fimage.png?alt=media\&token=c6e6897c-2b4d-4e37-a136-01135217ceb4)

#### &#x20;Output:

&#x20;Welcome to Home

&#x20;Welcome to Home: JSM

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTfNKnN7FirW1DQ4BZU%2F-LTfP0pqrb1xgiFxfzB_%2Fimage.png?alt=media\&token=6b1c10e6-ec07-4e92-98df-c1717a43a547)

#### &#x20;Output

&#x20;Area of square is4 Area of rectangle is6

&#x20;Area of circle is28.2599999999999

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTfNKnN7FirW1DQ4BZU%2F-LTfPIetVKVtMQavaAil%2Fimage.png?alt=media\&token=1546c12b-262f-436c-b6ee-0acd4fd3d041)

#### &#x20;Output:

&#x20;input recieved is: 10 input received is: 20.5

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTfNKnN7FirW1DQ4BZU%2F-LTfPUkuwXKzbqmDcSGm%2Fimage.png?alt=media\&token=e87763c4-3207-4cae-9ee4-43a602f78e73)

#### &#x20;Output:

&#x20;method test(int) is already defined in class

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTfNKnN7FirW1DQ4BZU%2F-LTfPnb3ULX7aQdmW6pu%2Fimage.png?alt=media\&token=ea8db88e-5524-4174-8c27-05e73390ee35)

#### &#x20;Output:

&#x20;Main(int a)

&#x20;Main(double a)
