Home Java Method overloading In JAVA

Method overloading In JAVA


In this topic, you will learn about, Method overloading In JAVA.

In case, it is possible to create methods that have the same name but different types of arguments or different numbers of arguments, this is called method overloading.

This overloading is used when objects are required to perform similar tasks but using different input parameters. When we call a method in an object JAVA matches up the method name first and then the number and type of parameter to decide which one of the definitions to execute.

this keyword

If a method wants to refer to the object through which it is invoked, it can refer to it by using this keyword.

We know that it is illegal to have two variables of the same name within the same scope of the program. this keyword is used to resolve any name conflict that occurs between instance variable and local variable. So, this keyword can be used to refer to the object directly. In the other words, this keyword is used inside an instance method to refer to the current object.

JAVA Program to show the use of this keyword:

Comment below if you have queries related to the above topic.



Please enter your comment!
Please enter your name here