Test Series - java

Test Number 59/64

Q: What is the output of the below code snippet?
public class Varargs5
{
  Varargs5(int...weights, boolean yesno)
  {
    System.out.println("AMAZON");
  }
  public static void main(String[] args)
  {
   //new Varargs5(20, true);
  }
}
A. No output
B. Error: The variable argument type int of the method Varargs5 must be the last parameter
C. Error: Varargs do not allow other data types
D. None
Solution: Yes. The compiler throws errors "Unresolved Compilation Problem" and "The variable argument type of the method or constructor must be the last parameter"
Q: Which is the operator used to represent a Vararg type in a method or constructor in Java?
A. One Dot (.)
B. Two Dots (..)
C. Three Dots (...)
D. DOT DOT DOT COMMA (...,)
Solution: The data type (primitive or object) immediately followed by three dots and a variable name separated by a space create a Variable Argument.
Q: How many maximum numbers of Varargs or Variable-Arguments can be there in a method or a constructor in Java?
A. 1
B. 8
C. 2
D. 16
Solution: Yes, only one. Because a VARARG can be present only as the last parameter or argument.
Q: What is the maximum number of methods or constructors with Varargs in a single Java class?
A. 1
B. 2
C. 8
D. There is no limit
Solution: Yes. There is no limit. There can be any number of methods or constructors with one Vararg per each method or constructor.

You Have Score    /4