public class A {

public void add(){ }

public void add(int a, int b){}
//1.Overloading (Same method name(add), different no. of arguments)                         


public void add(int a, int b, float c){}
//2.Overloading (Same method name(add), different no. of arguments)

public void add(String a, String b){}
//3.Overloading(Same method name(add),different argument)

public float sum(float a, float b) { return a+b;}

public float sum(float a, int b) { return a+b;}
//1.Overloading (Same method name (sum),different arguments, same return type)

public int sum(int a, int b) { return a+b;}
//2.Overloading(Same method name(sum),different arguments, different return type)

public double sum(float a, float b,int c) { return a+b;}
//3.Overloading(Same method name (sum),different no. of arguments, different return type)

//public double sum(float a, float b) { return a+b;}
// 4.Error:Duplicate method sum(float, float)
//Not a Valid Overload (Can't change only the return type)

}

 


Comments




Leave a Reply