Welcome Guest | Sign in | Register
Assertions - Discussion Page For Q.2549 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Assertions > Questions and Answers

Q:
public class Test {
public static void main(String[] args) {
int x = 0;
assert (x > 0): “assertion failed”;
System.out.println(“finished”);
 }
 }
What is the result?
A. finished B. Compilation fails.
C. An AssertionError is thrown. D. An AssertionError is thrown and finished is output.

Answer and Explanation

Answer:Compilation fails.

Explanation:
This question is a bit tricky because it lacks the following information: It should include a
statement that says whether or not assertions are enabled. If they are indeed enabled, the
correction answer is C. but if they are not, the correct answer is A. Assertions are not enabled by default so if the question is not changed, the most logical answer is A.

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved 2012-2015 SoftLucent.