Java OOPC -Method Overloading

 

  Method Overloading


       




In a same class we can keep same name methods with different parameters  this concept we called it as Method Overloading or can tell as Method Signature Changing. 

In because of the different parameters ,Method considered as completely different method from the same name other methods.

 

In other way can tell that Method overloading is a concept of Java in which we can create multiple methods of the same name in the same class, and all methods work in different ways. 

When more than one method of the same name is created in a Class, this type of method is called the Overloaded Method.

 

In bellow sample code we can understand overloading in different views,





Advantages of method overloading

1.      Increases the readability of the program.

2.      Makes the code cleaner and well-structured.

3.      Provides code reusability.

 

 

If we see an example ,




Here there are two more demo methods One takes an integer and a double, and the other takes a double and an integer. 

When call demo(10, 5.5), the method with an integer and a double parameter is invoked. When  call demo(5.5, 10), the method with a double and an integer parameter is invoked.

 

And this process go on output show as bellow.




 

Comments

Popular posts from this blog

Linked List Data Structures

Java OOPC -Encapsulation

React