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

Home > Java Programming > Assertions > Questions and Answers

Q: What is the output for the below code ?

public class Test {
public static void main(String... args) {
for(int i = 2; i < 4; i++)
for(int j = 2; j < 4; j++)
if(i < j)
assert i!=j : i;
}
}
A. The class compiles and runs, but does not print anything. B. The number 2 gets printed with AssertionError
C. The number 3 gets printed with AssertionError D. compile error

Answer and Explanation

Answer:The class compiles and runs, but does not print anything.

Explanation:
When if condition returns true, the assert statement also returns true.
Hence AssertionError not generated.

Comment on this Question

Name:

Loading...




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