Java OCA OCP Practice Question 1426

Question

How many lines does this program print?

import java.time.*; 
public class Main { 
   public static void main(String... nums) { 
     LocalDate time = LocalDate.of(1, 11); 
     while (time.getHour() < 1) { 
        time.plusHours(1); /*from   w  ww. j ava  2 s.  co  m*/
        System.out.println("in loop"); 
     } 
   } 
} 
  • A. None
  • B. One
  • C. Two
  • D. This is an infinite loop.
  • E. The code does not compile.


E.

Note

The LocalDate class is only for day/month/year values.

It does not support time, so getHour() and plusHours() do not compile, making Option E the answer.




PreviousNext

Related