Overloading

Overloading:
Overloading means creating more than a single method with the same name with different signature. In the example three methods are created with the same name.Java understands these methods with there signature java identifies the methods by comparing their signature like return types, constructor parameters & access modifier used.

Overloading
Overloading

class Adder{  
2.static int add(int a,int b){return a+b;}  
3.static int add(int a,int b,int c){return a+b+c;}  
4.}  
5.class TestOverloading1{  
6.public static void main(String[] args){  
7.System.out.println(Adder.add(11,11));  
8.System.out.println(Adder.add(11,11,11));  
9.}}  
Test it Now 
Output:

22
33
Translate »