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

Discussion

The program is run with java -ea -da Sample37 - what will be the output?

public class Sample37
{
    public static void main(String[] args)
    {
        double rate = 0.0;
        assert rate > 0.0 : "rate not set";
        System.out.println("rate " + rate);
    }
}

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

Answer: A

Neither switch carries an argument, so both apply to the same set of classes and the later one settles it: assertions end up disabled, the check is skipped and the program prints rate 0.0. Ordering only decides the outcome when two switches have the same specificity; a more specific switch beats a general one wherever it appears.

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

Post your comment

Please log in or register to post a comment.