• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Dan's assertion question:

 
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Question 20
An assert statement can be used to check a control-flow invariant to verify which of the following?
a. A particular assumption is true when the flow of control enters a method.
b. The flow of control does not reach a particular point in the program.
c. The normal flow of control has reached a particular point in the program.
d. The normal flow of control has reached the end of a method.
e. The default case of a switch statement is not reached.
f. The else block of an if/else statement is not reached.


I think all of the above answer are correct. But given ansers are b,e, and f. What do you think?
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assertions can be used for checking a conditional branch that should not be reached...

This makes for e and f. b is a generalization of both.
Notice that with the assertion we check a conditional result not that we have reached the beginning or end of a method.
In Control flow invariants from Programming with Assertions we check a conditional, not any other point in a method.
The examples above are from The Java 1.4 Tutorial by Gregory M. Travis , which says "Do use (assertions) to check for conditional cases that should
never happen" . Not for the flow of control reaching any point in a method.
a is true as a general assertion guideline, but not for the "control flow invariant"
 
Something must be done about this. Let's start by reading this tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic