Ads Sponsored By Google :)

Sunday 13 January 2013

Definition|Define of method overloading in java with|of example


method overloading in java method overloading example in java method overloading in java with example method overloading in java example example of method overloading in java method overloading program in java Define method overloading Definition of method overloading method overloading in java definition method overloading in java example


    Method Overloading  :
   
   Definition:
         Method overloading in which its method name is same but its signature is different.
     Signature represents the following points
     a)      Number of parameters
     b)      Types of parameters
     c)       Order of parameters

    While we are overloading the method return type is not considered.

    The Following Program illustrate the concept of Method overloading
  
     Class demo
   {
        int sum(int x,int y)
      {
         int z=x+y;
         return z;
       }
       float sum(float x)
      {
        float z=x+9.o;
        return z;
      }
      void sum(char x)
     {
       System.out.println(“this is sum method of char as formal parameter”+x);
     }
   }
    Class maindemo
  {
       public static void main(String args[])
     {
       System.out.println(“this is main method”);
       int  p=sum(10,20);
       float q=sum(19.9);
      sum(‘a’);
     }
   }

  Analysis:
        The above example in which it contains sum() method is overloaded because 
  all three method names are same but its signature is different. sum(int x,int y),
  sum(float x), sum(char x) of same name sum and its signature number of
  parameters are 2,1,1 respectively, and its Type of parameters (int,int), (float), 
  (char) and order of parameter is different.
                                                               Then we say that method sum() is oveloaded.

No comments:

Post a Comment

LinkWithin