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

Home > Java Programming > Assertions > Questions and Answers

Q:
Public class Foo{
public void m1( int value ){
assert 0 <= value;
System.out.println( "OK" );
}
public static void main( String[] args ){
Foo foo = new Foo();
System.out.print( "foo.m1( 1 ): " );
foo.m1( 1 );
System.out.print( "foo.m1( -1 ): " );
foo.m1( -1 );
}
}

Predict the output of code if it is assert enabled?
A. OK B. OK OK
C. OK then triggers an assertion error D. None of these

Answer and Explanation

Answer:OK then triggers an assertion error

Explanation:
assert expression1;
assert expression1 : expression2;
In each form, expression1 is the boolean-typed expression being asserted. The expression
represents a program condition that the developer specifically proclaims must be true during program execution. In the second form, expression2 provides a means of passing a String message to the assertion facility

Comment on this Question

Name:

Loading...




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