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

Discussion

The program is run with java -ea:com.acme.io... com.acme.util.Example31 - what will be the output?

package com.acme.util;

public class Example31
{
    public static void main(String[] args)
    {
        int total = 0;
        assert total > 0 : "total was " + total;
        System.out.println("total " + total);
    }
}

  • A.No output is produced.
  • B.An AssertionError is thrown.
  • C.The program prints total 0
  • D.Compilation fails.

Answer: C

Assertions are enabled only for com.acme.io and its subpackages. The class is in com.acme.util, a sibling of that package rather than a subpackage of it, so it keeps assertions disabled and the false assertion is skipped. Sharing the prefix com.acme is not enough.

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

Post your comment

Please log in or register to post a comment.