Java OCA OCP Practice Question 2524

Question

Which of the answer choices is printed out by the following code?

String d = Duration.ofDays(1).toString(); 
String p = Period.ofDays(1).toString(); 
? 
boolean b1 = d == p; 
boolean b2 = d.equals(p); 
System.out.println(b1 + " " + b2); 
  • A. false false
  • B. false true
  • C. true false
  • D. true true
  • E. The code does not compile.
  • F. A runtime exception is thrown.


A.

Note

d is the String P1D and p is the String PT24H.

They are neither the same object nor the same value.

Remember that Duration uses hours/minutes/seconds and Period uses years/months/days for measures.




PreviousNext

Related