This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Assertion question doubt?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Assertion question doubt??" Watch "Assertion question doubt??" New topic

Assertion question doubt??

Amit Das
Ranch Hand

Joined: Mar 05, 2005
Posts: 206
hi all,

answer given is E........
but i think here assertion has been used appropriately throughout....
well if i give a little more thought, E may be correct because at line 18 the 2nd expression although returns a value but changes the value of local variable z, which changes the state.....may be!!!

plz have ur say on this...

Sajid Moinuddin
Ranch Hand

Joined: Mar 19, 2005
Posts: 85
you can but it is not appropiate to use assersion to apply any logic that change the state of the object. think when you are running the code with assertion Off. your condition might fail but the change you were expecting doesn't take place. Keep one thing in mind...assertions are enabled while developing.Once you finish your development, the deployed application usually has assertion disabled. so in that case, your logic fails. Use assertion only for debugging option , not like a if -else block.
hope u got the point.
Consider Paul's rocket mass heater.
subject: Assertion question doubt??
Similar Threads
"assert i%2==0 : i--;"question required
two possible answers Q18 ch 4 page 282 from KB