GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Dan's Comprehensive Mock Exam 10, Question 30 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 "Dan Watch "Dan New topic
Author

Dan's Comprehensive Mock Exam 10, Question 30

John Hembree
hired gun
Ranch Hand

Joined: Mar 07, 2003
Posts: 250


Part of the answer states: 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.
This doesn't make sense to me since the assert statement is outside of the If statement unless I didn't match up the braces correctly. The assert statement would fire every time regardless of the flow thru the if's. If it had been written

then I could buy into this answer.
I'm probably missing something, so I submit myself to those more knowledgable. I haven't found anything else where Dan's code and answers weren't 100% correct, so I'm sure I'm overlooking something, but what?
John Hembree
hired gun
Ranch Hand

Joined: Mar 07, 2003
Posts: 250

I could buy into the answer also if the code resembled this as well:

but it appears that regardless of the value of b1 and b2 that "assert false" will execute.
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
John,
Thank you for pointing out that error. Your first assumption is consistent with what I was thinking when I developed that question. It should be as follows.

I'll upload the correction now.
Thank you!


Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
 
GeeCON Prague 2014
 
subject: Dan's Comprehensive Mock Exam 10, Question 30