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.
Ans. No. Because java internally treats var args as arrays and hence both method declarations will generate the same byte code and hence would result in ambiguity while determining call binding.
Help us improve. Please let us know the company, where you were asked this question :
Var Args argument should have data type followed by three dots
Three dots should be consecutive and not separated by even space
We cannot have space before and after the dots
If there is a var args in the method, it should be only one and the last one.
Which of the following is not valid var args declaration ?
int sum (int... numbers)
int sum (.int .. numbers)
int sum (int ... numbers)
int sum (int x, int ... numbers)
Q5. Which of the following is false about var args ?
a. Var Args argument should have data type followed by three dots b. Three dots should be consecutive and not separated by even space c. We cannot have space before and after the dots d. If there is a var args in the method, it should be only one and the last one.
Ans. We cannot have space before and after the dots
Help us improve. Please let us know the company, where you were asked this question :
Ans. Var args is the feature of Java that allows a method to have variable number of arguments. Var args are used when we are not sure about the number of arguments a method may need. Internally java treats them as array.
Ans. Yes, it will give compilation error and java will complain about duplicate method. Java treat var args internally as arrays and hence would result in same byte code for both method's syntax.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Though var args are used rarely but they are pretty useful if a method is expected to receive variable number of arguments. For example - it's pretty useful for the main method as the caller has the flexibility to provide arguments in infinite ways.It provides a convenience and flexibility to the caller.
Help us improve. Please let us know the company, where you were asked this question :