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

Discussion

Which line contains the error?

package com.acme.core;

public class Sample46
{
    public static void main(String[] args)
    {
        int stock = -1;
        assert stock >= 0 : stock;
        System.out.println(stock);
    }
}

  • A.System.out.println(stock);
  • B.Nothing is wrong with the code itself.
  • C.assert stock >= 0 : stock;
  • D.package com.acme.core;

Answer: B

Nothing is wrong with the code. The mistake people make with it is at the command line: running java -ea:com.acme... com.acme.core.Sample46 enables the check, but -ea:com.acme.core without the three dots names a CLASS, and no class has that name, so assertions stay off and the negative stock passes unnoticed.

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

Post your comment

Please log in or register to post a comment.