Monday 10 July 2017

Method Overloading Java

Shahzaib Khan
Student Of Sir Syed University
Karachi, Pakistan.



                       Method Overloading Java

Assalam-o-Alaikum Friends:

Method Overloading is the Type of Polymorphism. Which means many form. we can easily understand what is method Overloading by this following Examples. method refers to function and overloading refers to methods of same name in a Class. but thing is this that the datatype of methods is not same.In real life Example we Can say that the name for example Ali is the name of many students in a school but they all are studying in a different levels by name they are same but their working or activity are not same.before  the implementation of the code we need to familiar with Methods and its Type. lets take an example by code in Java:

public class school
 {

public int working(int a , int b)
{
return a+b;
}
public float working(float a ,float b)
{
return a+b;
}
public String working(String a , String b)
{
return a+b;
}
public double working(double a , double b)
{
return a+b;
}
}

class  program{

public static void main(String[] args) {


school s = new school();
s.working(5,10);
s.working("My", "_Class");
s.working(5.6,10.9);
s.working(123.42, 434.89);
System.out.println("int's activity  "+s.working(5,10) );
System.out.println("string's activity"+s.working(("My", "_Class")) );
System.out.println("float's  activity"+.s.working(5.6,10.9) );
System.out.println("double's activity"+s.working(123.42, 434.89) );
         }

}

Output :

int's activity 15
string's activity My_Class
flaot's activity 16.5
double's activity 558.31

}
}

This is the simplest example of Method Overloading. Hope you people got the basic idea of Method Overloading from this post.
Thank you