What is Method overloading in JAVA


               As we know,  java class have variables and methods. I will suggest to read starting with java program post before reading this. Whether the methods  present in the class can  have same name ? Yes .Methods with same name can exists  in the class  after meeting the following criteria
           i]. Number of parameters should be different
          ii]. If the number of parameters are same, the datatype should be different
        iii]. Order of the parameters should be different.

For example:
             void add(int var1,int var2);
         void add(int var1,int var2,int var3);
         void add(int var1,float var2,long var3);
         void add(float var1,int var2,long var3);

Method overloading cannot be achieved by means of return type
     e.g.   void add(int var1,int var2);
             int  add( int var1,int var2);

The above scenario is not method overloading.


Previous
Next Post »