Sunday, June 22, 2014

Method Overloading

method overloading | java method overloading | overloaded method

Method Overloading is the concept of object oriented programming in which a class having two methods with the same name but different parameter.”
In Java we have two ways to overload the method, one is to by changing the number of arguments and other is to by changing the data type in the time of declare a method. When an overloaded method is invoked, Java matches up the method name and the number and type of arguments to choose which method definition to execute. But remember that Java differentiates overloaded method with the same name, based on the number and type of parameters to that method, not on its return type. So, if you try to create two methods with the same name and same parameter list, but different return types, you’ll get a compiler error.

Example of Method Overloading in Java: -

  • By changing the number of arguments

  • By changing the data type
                                     Figure: -Example of method overloading in Java

No comments:

Post a Comment