• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Sybex Java OCA/OCP Practice test 8 ch10 question 76 mistake

 
Ranch Hand
Posts: 216
11
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.time.*;
public class OnePlusOne {
   public static void main(String... nums) {
       LocalDate time = LocalDate.of(1, 11);
       while (time.getHour() < 1) {
           time.plusHours(1);
           System.out.println("in loop");
       }
   }
}

76. E. 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.

It does not explain the fact that LocalDate.of(1, 11); does not compile because it should be LocalDate.of(1,11,1); It needs 3 arguments(int,int,int).Compile error if it has less than 3.
 
author & internet detective
Posts: 42109
934
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Confirmed and added to the errata. While this was not in the Java 11 book, we may use it for Java 17. (Dates are back in scope.)

Hopefully the editing process would have caught it this go round. But even better that you caught it first. Have two cows!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic