Skip to main content

Method Overloading in Java Best Example For Biggeners and Students.

  1. class plus{  

  2. static int add(int a,int b)
  3. {
  4.     return a+b;
  5. }  

  6.    static int add(int a,int b,int c) 
  7.    {
  8.       return a+b+c;
  9.    }  
  10. }  

  1. class Overloading1
  2. {  
  3. public static void main(String[] args)
  4.    {  

  5.       //access the add method with 2 param from class plus,
  6.      //pass 2 arguments and print the return value
  7.      System.out.println(plus.add(10,10));  

  8.       //access the add method with 3 param from class plus, 
  9.       //pass  3 arguments and print the return value
  10.       System.out.println(plus.add(10,10,10));  
  11.     }
  12. }  

It will produce the following results:

20
30

Comments