Java OCA OCP Practice Question 883

Question

How many lines does the following code output?

String[] days = new String[] { "Sunday", "Monday", "Tuesday", 
           "Wednesday", "Thursday", "Friday", "Saturday" }; 
for (int i = 0; i < days.size(); i++) 
           System.out.println(days[i]); 
  • A. Six
  • B. Seven
  • C. The code does not compile.
  • D. The code compiles but throws an exception at runtime.


C.

Note

The code days.size() would be correct if this was an ArrayList.

Since it is an array, days.length is the correct code.

Therefore, the code does not compile, and Option C is the answer.




PreviousNext

Related