This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dan's Comprehensive Mock Exam 10, Question 30

 
John Hembree
hired gun
Ranch Hand
Posts: 250
MS IE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 250
MS IE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic