COMPILER DESIGN

ADVANCED TOPICS IN COMPILER DESIGN

CODE GENERATION FOR OBJECT ORIENTED LANGUAGES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Which is the correct syntax of varargs in Java?
A
return ____ type method ____ name(variableName data ____ type ____ ){}
B
return ____ type method ____ name(data ____ type ____ variableName){}
C
return ____ type method ____ name(data ____ type variableName ____ ){}
D
None of the above
Explanation: 

Detailed explanation-1: -12) Which is the operator used to represent a Vararg type in a method or constructor in Java? A) One Dot (.) Explanation: The data type (primitive or object) immediately followed by three dots and a variable name separated by a space create a Variable Argument.

Detailed explanation-2: -A method with variable length arguments(Varargs) in Java can have zero or multiple arguments. Variable length arguments are most useful when the number of arguments to be passed to the method is not known beforehand. They also reduce the code as overloaded methods are not required.

Detailed explanation-3: -Varargs help us avoid writing boilerplate code by introducing the new syntax that can handle an arbitrary number of parameters automatically – using an array under the hood.

There is 1 question to complete.