Advertisement
Virajsinh

Java_03

Jan 28th, 2018
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. // Write a java Program which explain the possible three ways of method overloading.
  2.  
  3. class Ex3 //Ex3 is Java Program Name
  4. {
  5.     public void add(int a, int b)
  6.     {
  7.         System.out.println(a+b);
  8.     }
  9.    
  10.     public void add(int a, int b, int c)
  11.     {
  12.         System.out.println(a+b+c);
  13.     }
  14.    
  15.     public void add(int a, double b)
  16.     {
  17.         System.out.println(a+b);
  18.     }
  19.    
  20.     public void add(double a, int b)
  21.     {
  22.         System.out.println(a+b);
  23.     }
  24.    
  25.     public static void main(String a[])
  26.     {
  27.         Ex3 obj = new Ex3();
  28.        
  29.         obj.add(1,2);
  30.         obj.add(1,2,3);
  31.         obj.add(1,1.2);
  32.         obj.add(1.2,1);
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement