Saturday 30 July 2016

Method Overloading in Java



Method Overloading in Java

When two or more methods having same name but different parameters or types is known as Method Overloading. Method overloading increases the readability of the program. Method Overloadingis also known as Static Polymorphism.

Different ways of overloading the method

Ans. There are two ways of method overloading in java.
1) By changing number of arguments or parameters
2) By changing the data type (int, float, double)

Simple Example of Method Overloading with different parameters: -

Example1: -

class demo
{
          void display()
          {       
                   System.out.println("Hello Safal");
          }
          void display(int a)
          {       
                   System.out.println(a);
          }
}
class funover       //save the by funover.java
{
public static void main(String args[])
          {
                   demo s = new demo();
                   s.display();
                   s.display(5);
          }
}
OUTPUT:-
Hello Safal

No comments:

Post a Comment