Java OCA OCP Practice Question 1751

Question

What is the result of executing the following application with assertions enabled?

1: package mypkg;
2: public class Main {
3:    public static void main(String[] bricks) {
4:       int flakes = 10;
5:       double assert = 7.0;
6:       assert (true :"");
7:       assert flakes++>5;
8:    }
9: }
  • A. It throws an AssertionError at runtime.
  • B. It prints nothing at runtime.
  • C. Exactly one line of code does not compile.
  • D. Two lines of code do not compile.


D.

Note

In Java, assert is a keyword, meaning it cannot be used as a variable, class, or method name.

Line 5 does not compile.

Line 6 also does not compile because the assert statement is not a method and does not support parentheses around both expressions.

Because neither of these lines compile, Option D is the correct answer.




PreviousNext

Related