Java Method Overloading With Examples

Java Method Overloading With Examples

Define :

  • Method overloading simply means various methods having same name.
  • If the methods have the same name, how can Java know which method you mean? There’s a simple rule: Each overloaded method must take a unique list of argument types.
  • If you think about this for a second, it makes sense. How else could a programmer tell the difference between two methods that have the same name.
  • Even differences in the ordering of arguments are sufficient to distinguish two methods, although you don’t want to take this approach because it makes the code hard to maintain.
  • We will see few examples as follows -

Example1 -

Output -

Example 2 -

Output :