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); } }
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?
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?
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?
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 |