|
|
350 Mock Questions on SCJP 1.5 - JUST Rs.200 or 7 USD
Send us mail to sales@javabeat.net
more details
|
|
SCJP 5.0 - VarArgs Mock Questions - 1
1) What is the result of compiling and running the following code?
class VarArgOne {
public static void printArgs(String s, Integer ... i, String s) { //line 1
for(int j : i) { //line 2
System.out.print(j + " " + s); //line 3
}
}
public static void main(String ... args) { //line 4
printArgs("exam", 12, 34, "scjp"); //line 5
}
}
a) Compilation fails due to error at line 1.
b) Compilation fails due to error at line 2.
c) Compilation fails due to error at line 4.
c) Compilation fails due to error at both line 1 and line 4.
d) Compiles fine and Prints output "12 scjp 34 scjp".
Answer:
1)A
The var-arg must be the last parameter in the method's signature. Here it is followed by another argument.
B is incorrect, var-args variable can be used in enhanced for loop(Tiger loop).
c is incorrect, we can use var-args in the place of String [] in main method.
|
|
350 Mock Questions on SCJP 1.5 - JUST Rs.200 or 7 USD
Send us mail to sales@javabeat.net
more details
|
|