web analytics

When we write two methods in a class with the same name but with different no. of parameters then we can say that the method can be overloaded.

Example :

Class AreaCalculator{

public static void main(String args[]){

int l,b,h;

AreaCalculator calculate=new AreaCalculator();

calculate.area(l,b);

calculate.area(l,b,h);

}

public int area(int x,int y){

return x*y;

}

public int area(int x,int y,int z){

return x*y*z;

}

}

In the above example we can say that method area can be OVERLOADED, as the method name is same but the no. of parameters is different.

Categories: Java

Leave a Reply

Your email address will not be published. Required fields are marked *