Discussion :: Assertions - Pointing out the errors (Q.No.1)
Starrer said: (Sep 13, 2014) | |
Why the answer is 22 and not 11? |
Nikola said: (Sep 16, 2015) | |
Why the answer is 22 and not 12? At line 12 also z is changed? |
Vspider said: (Aug 27, 2020) | |
Assertion is majorly used to debug any java code. In option D it is changing the value of variable which effects the flow of code i.e. it changes the further working of code. Now in option B the value of z is not changed because of assertion but is changed because of function. And the value of 'z' is same even after the call. Where as in Option D assertion changes the value keep in mind that assertion is for debugging and not for modifying. That is why we use it on private variables whose scope is limited to class and change is detected there itself. We avoid using assertion on public variables. |
Post your comments here:
Name *:
Email : (optional)
» Your comments will be displayed only after manual approval.