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

Discussion

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

package com.acme.util;

public class Fragment30
{
    public static void main(String[] args)
    {
        assert false;
        System.out.println("ran");
    }
}

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

Answer: B

The trailing three dots mean the named package and all of its subpackages. Fragment30 is in com.acme.util, so assertions are enabled for it, the false assertion is evaluated and an AssertionError is thrown before the print. Without the dots the switch would name a class rather than a package.

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

Post your comment

Please log in or register to post a comment.