• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Assertion question from Dan's exam

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://www.danchisholm.net/dec04/topic/section2/assertions2.html
Question 9

Which statements are true?
a. With assertions enabled it prints an AssertionError message.
b. With assertions enabled it prints nothing.
c. With assertions disabled it prints an AssertionError message.
d. With assertions disabled it prints nothing.
e. An assertion should not be placed at any location that the programmer believes will never be reached under normal operating conditions.
f. The assert statement is being used to check a control-flow invariant to verify that the control flow never reaches a point in the program.
g. A compiler error is generated.
h. None of the above.

According to the answers option "f" is correct
But in this code assert statement is placed at a place where it will always be called no matter what is the value of b1,b2,b3, since there are no return statements in the if-the-else statements.
I feel "f" may not be the correct option.
Dan can you pls confirm !
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shweta,
You are correct. The assert statement should be in an "else" block as shown below.

The correct answers are still A,D and F.
I will upload the correction.
Thank you!
 
shweta mathur
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Dan !
Your questions are really interesting to work on !
Shweta
 
That's a very big dog. I think I want to go home now and hug this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic