Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which line contains the error?

public class Sample90
{
    public static void main(String[] args)
    {
        int age = 30;
        assert (age > 0);
        System.out.println(age);
    }
}

  • A.System.out.println(age);
  • B.No line here is in error.
  • C.assert (age > 0);
  • D.int age = 30;

Answer: B

Nothing here is wrong. assert is a statement rather than a method, but wrapping its condition in parentheses is still valid, because those simply group the expression. It compiles, the condition is true and the program prints 30. The parentheses are redundant, not an error.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.