Search Interview Questions | More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know. |
|
| ||||
Interview Questions and Answers | ||||
| ||||
Ans. 1st is a valid and standard declaration. 2nd results in compilation error as only 2 dots are there. 3rd results in compilation error as three dots are not consecutive and broken. 4 through 6 may not be standard and ideal way of declarations but they are valid and will compile and work fine. 7 is valid declaration. 8 and 9 will result in compilation error as var args can only be provided to last argument. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  var args  methods  functions   method declaration  scjp  ocjp | ||||
Related Questions | ||||
What is the difference between these two method declarations ? private static void method(String[] arg) and private static void method(String... arg) | ||||
Can we overload method as following ? void method(int... x){}; void method(int[] x){}; | ||||
Which of the following is not valid var args declaration ? | ||||
Do you prefer using var args ? | ||||
Which of the following is false about var args ? | ||||
What are var args ? or What is the use of var args ? | ||||
Why following method declarations are not valid ? void method(int... x, int y){}; void method(int... x,int... y){}; | ||||
Which method will get called if we call it as method(1) void method(int x ){}; void method(int... x){}; | ||||
Do you see any problem with this code public class BuggyBread { public static void main(String[] args) { method("Hello","World"); } private static void method(String... args){ for(String arg:args){ System.out.println(arg); } } } | ||||