Java OCA OCP Practice Question 556

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.length; 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.


B.

Note

There is nothing wrong with this code.

It correctly creates a seven-element array.

The loop starts with index 0 and ends with index 6.

Each line is correctly output.

Therefore, Option B is correct.




PreviousNext

Related