This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Which statements are true? a. With assertions enabled it prints "ABC" followed by an AssertionError message. b. With assertions enabled it prints "ABCE" followed by an AssertionError message. c. With assertions disabled it prints "ABC" d. With assertions disabled it prints "ABCE" e. Assertions should not be used within the default case of a switch statement. f. A compiler error is generated. g. None of the above. //save as: C.java and compile it: //C.java:8: warning: as of release 1.4, assert is a keyword, and may not be used a s an identifier assert false; ^ C.java:8: not a statement assert false; ^ C.java:8: ';' expected assert false; ^ 2 errors 1 warning The correct answer is A ,D, but why? Thank you for your help!!
[Dan added formatting.] [ February 27, 2003: Message edited by: Dan Chisholm ]
I want to pass SCJP for 1.4 !I am very grateful to you for helping me!!
You must use a special switch to compile code that contains assertions: javac -source 1.4 C.java In future versions of Java assertions may be enabled by default, but as of JDK 1.4 you must explicitly enable the compilation of assertions. This was done to allow code that compiled under previous versions of the JDK to compile under JDK 1.4. [ February 27, 2003: Message edited by: John Paverd ]
Joined: Feb 15, 2003
Thank you ,John Paverd!! but i am still confused. I try : javac -source 1.4 C.java //compile success java C //output: ABCE Why the output is the same as that without no statement(assert false ?