Question 2

10. public class Bar {
11.static void foo(int...x) {
12. // insert code here
13. }
14. }
Which two code fragments, inserted independently at line 12, will allow
the class to compile? (Choose two.)
A. foreach(x) System.out.println(z);
B. for(int z : x) System.out.println(z);
C. while( x.hasNext()) System.out.println(;
D. for( int i=0; i< x.length; i++ ) System.out.println(x[i]);

Answer: BD


type... x is used in function arguments where type can be any data type
for example:
int... x

which can take variable arguments
for example a function named var having declarations

var(int... x)

we can pass var(1); , var(1,1); , var(1,2,3);

so it can take 1 to any number of integers as arguments

int... x here x is just like an array and we can iterate over its elements using simple and enhanced for loop

other options are invalid

foreach is a method which is not defined
And hasnext() is used to iterate over collections(sets,lists,maps)

Hence the answer is B,D


Anonymous said...

Sun Java Certification (Newbie)


Nimesh Kumar said...

When preparing for java certification, you must practice mock exams to check your readiness. You can check out some free java certification mock exams to practice. provides 500+ free practice questions with web based exam simulator, and most importantly, you can save your test session and later try only incorrectly answered question.

TV de LCD said...

Hello. This post is likeable, and your blog is very interesting, congratulations :-). I will add in my blogroll =). If possible gives a last there on my blog, it is about the TV de LCD, I hope you enjoy. The address is A hug.

Krishna said...

Here you can find the quality SCJP 1.5 questions,
SCJP 1.5 Questions

Post a Comment