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

Discussion

Which line will cause a compilation error?

public class Sample81
{
    static final int MAX = 10;

    public static void main(String[] args)
    {
        assert MAX = 20;
        System.out.println(MAX);
    }
}

  • A.assert MAX = 20;
  • B.static final int MAX = 10;
  • C.System.out.println(MAX);
  • D.Nothing here is wrong.

Answer: A

Two faults meet on one line and the compiler reports both: a final field cannot be assigned, and the assignment yields an int where a boolean is required. Either alone would be fatal. The author almost certainly meant ==.

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

Post your comment

Please log in or register to post a comment.