• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Contradiction between two Qs - Help!!!

 
Manikandan Jayaraman
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Manikandan Jayaraman
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic