Java OCA OCP Practice Question 3039

Question

Given this program:

import java.time.*;
import java.time.temporal.ChronoUnit;

class Main {// ww w . j a  va  2s.  com
    public static void main(String []args) {
        Duration tenYears = ChronoUnit.YEARS.getDuration().multipliedBy(10);
        Duration aDecade = ChronoUnit.DECADES.getDuration();
        assert tenYears.equals(aDecade) : "10 years is not a decade!";
    }
}

Assume that this program is invoked as follows:

java Main

Choose the correct option based on this program:

  • a) this program does not compile and results in compiler error(s)
  • b) When executed, this program prints: 10 years is not a decade!
  • c) When executed, this program throws an AssertionError with the message "10 years is not a decade!"
  • d) When executed, this program does not print any output and terminates normally


d)

Note

the program compiles cleanly without any errors.

assertions are disabled by default.

Since assertions are not enabled when invoking this program, it does not evaluate the assert expression.

hence, the program terminates normally without printing any output on the console.




PreviousNext

Related