| Author |
on assertions
|
velan vel
Ranch Hand
Joined: Nov 15, 2005
Posts: 137
|
|
hai here bydefaultly the assertions are disabled so it should print finished but why this code is giveing compile time error Given: 1. public class Test { 2. public static void main(String[] args) { 3. int x = 0; 4. assert (x > 0) ? "assertion failed" : "assertion passed"; 5. System.out.println("Finished"); 6. } 7. } What is the result? A. finished B. Compilation fails. C. An AssertionError is thrown and finished is output. D. An AssertionError is thrown with the message "assertion failed". E. An AssertionError is thrown with the message "assertion passed". Answer: B by velan vel
|
 |
Niranjan Deshpande
Ranch Hand
Joined: Oct 16, 2005
Posts: 1277
|
|
assert (x > 0) ? "assertion failed" : "assertion passed"; the two syantaxes for assert statments are 1. assert expression1; 2. assert expression1:expression2; u r using something like (but not exactly) case 2. the expression is incorrect...and does not exqactly return boolean value in ur case < (x>0) ? "assertion failed" ) turns out to be expression 1 and it doesnt return a boolean hence compiler error
|
SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
|
 |
 |
|
|
subject: on assertions
|
|
|