File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Contradiction between two Qs - Help!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Contradiction between two Qs - Help!!!" Watch "Contradiction between two Qs - Help!!!" New topic
Author

Contradiction between two Qs - Help!!!

Manikandan Jayaraman
Ranch Hand

Joined: Sep 15, 2004
Posts: 230
I was taking some revision tests from http://www.danchisholm.net/july21/mybook/chapter23/assertions1.html on Assertions and was confused by the confusion caused between two queries. The queries are given below.

=================
Question 14:

Which statements are true?

a. If assertions are enabled at run time it prints an error message.
b. With assertions enabled it prints nothing.
c. With assertions disabled it prints an error message.
d. With assertions disabled it prints 1112.
e. With assertions disabled it prints nothing.
f. The assert statements are being used to check a precondition--something that must be true when the method is invoked.
g. Method m1 is an example of an improper use of an assert statement: an assert statement should not be used for argument checking in a non-public method.
h. Method m2 is an example of an improper use of an assert statement: an assert statement should not be used for argument checking in a public method.

==========

Question 17

Which statements are true?

a. If assertions are not enabled at run time it prints an error message.
b. If assertions are not enabled at run time it prints nothing.
c. With assertions enabled it prints an error message.
d. With assertions enabled it prints nothing.
e. The assert statement is being used to check a class invariant--something that must be true about each instance of the class.
f. The assert statements are being used to check a precondition--something that must be true when the method is invoked.

=============

The confusion here is choice 'f' is there in the answer of Q14 but not included for Q17. Can anyone justify why ??
[ October 25, 2004: Message edited by: Barry Gaunt ]

Regards,<br />Mani<br />SCJP 1.4 (95%)<br />SCWCD 1.4 (94%)
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Option f. is in both questions as far as I can see. Do you mean option 17.e?

Anyway I can't see why the questions have to have the same options for their answers. Why should they?
[ October 25, 2004: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Manikandan Jayaraman
Ranch Hand

Joined: Sep 15, 2004
Posts: 230
Actually what I wanted to say is, The option which talks about "precondition check" using assertions was found in both the questions. But, in the answers for these questions, only Q14 had this choice in its answer and Q17 did not.

===
Does this choice talk about assertions in general ???
Should I consider that question alone, while considering the options or consider assertions in general?
===
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Well, Question 17 is not using assert for precondition checking, it doing a class invariant check. It's checking in the constructor and each of the methods that something is always true about the state of the object. So option 17.e is OK, and option 17.f is not.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Contradiction between two Qs - Help!!!