Consider
public void printInt(int a) public void printInt(int a, int b) public void printInt(int a, int b, int c) public void printInt(int...x) /*Ah! tricky one*/All above methods are overloaded. But what will be the output for this code?
printInt(1,2,3);My first guess was public void printInt(int...x) as it more generalized method definition. But, it's wrong answer.
First, the compiler will search for an overloaded method with exact number of arguments. If not found, it will go for method with variable number of arguments.
0 comments:
Post a Comment