| Author |
Can u explain this assert question
|
Supriya Nimakuri
Ranch Hand
Joined: May 23, 2006
Posts: 83
|
|
1. public class Test{ 2. public static void main( String[] argv ){ 3. // insert statement here 4. } 5. } Which statement, inserted at line 3, produces the following output? Exception in thread �main� java.lang.AssertionError: true at Test.main(Test.java:3) A. assert true; B. assert false; C. assert false : true; D. assert false == true; E. assert false: false; Which is correct option C or E..and why
|
 |
Karol Kisielewski
Greenhorn
Joined: Jun 28, 2006
Posts: 8
|
|
Originally posted by Supriya Nimakuri: 1. public class Test{ 2. public static void main( String[] argv ){ 3. // insert statement here 4. } 5. } Which statement, inserted at line 3, produces the following output? Exception in thread �main� java.lang.AssertionError: true at Test.main(Test.java:3) A. assert true; B. assert false; C. assert false : true; D. assert false == true; E. assert false: false; Which is correct option C or E..and why
Of course correct is C. If the first part of assert statement resolve to false, then AssertionError is thrown. The second part is the message which will be printed. The value of the message can be any expression which return some value. BTW. I had the same question on real exam. Where did you get it from?
|
 |
 |
|
|
subject: Can u explain this assert question
|
|
|