Could not understand java assert mechanism -


this program question in book of scjp questions

class 1 {     int x = 0;     {         assert x == 1;     } }  public class 2 {     public static void main(string[] args) {         int y = 0;         assert y == 0;         if(args.length > 0)             new one();     } } 

which of following run without error? options given are

a. java 2 b. java 2 x c. java -ea 2 d. java -ea 2 x e. java -ea:one 2 f. java -ea:one 2 x g. java -ea:two 2 x 

correct options a, b, c, e , g

reason given d , f incorrect is, instance of one created. don't understand why problem if instance of one created.

in option b , g also, instance of one created, why problem d , f?

i don't understand why problem if instance of one created.

because one contains assert guaranteed fail when instantiated (and options pass in args); 0 != 1 in

class 1 {     int x = 0;     {         assert x == 1;     } } 

further, in option b asserts not enabled , in option g asserts enabled in class two (and problematic assert in class one).


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -