Demonstrating Method Overloading


package OverLoadingSampleClass;

/**
 *OverLoading.java
 * @author SHASHI
*
* here we are demonstrating a basic example of overloading of methods
* the print method has 3 different parameters but the method name is same so a method having the same name but different parameter can be considered under method overloading method
 */
public class OverLoading {
   
  void  print(String s){                                     //metnhod with string parameter
        System.out.println("String through overloading is  "+s);
    }
 void  print (int i)                                               //method with int parameter
    {
       
        System.out.println("Integer no through overloading is "+ i);
    }
 void   print (String s, int i){                             //same method with string and int parameter
        System.out.println(" overloaded string is "+ s + " and overloaded integer is "+i);
    }




}
class  OverloadDemo {             //class made outside of package class to call the methods of that class
     
     public static void main(String[] args) {
          OverLoading ob = new OverLoading();
     
         ob.print("sj");
        ob.print(99);
        ob.print("reliance", 33);
     }
   
 }



********************************** output **********************************
String through overloading is  sj
Integer no through overloading is 99
 overloaded string is reliance and overloaded integer is 33

No comments:

Post a Comment