This week's book giveaway is in the Java in General forum. We're giving away four copies of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 and have ishori Sharan & Adam L Davis on-line! See this thread for details.
Which statement is true?
A. All of the assert statements are used appropriately.
B. Only the assert statement on line 2 is used appropriately.
C. Only the assert statement on line 5 is used appropriately.
D. Only the assert statement on line 8 is used appropriately.
E. Only the assert statements on lines 2 and 5 are used appropriately.
F. Only the assert statements on lines 2 and 8 are used appropriately.
G. Only the assert statements on lines 5 and 8 are used appropriately.
Can someone explain why ?
Yes, as AmanZeek said,
* it's not reccommended to use assertions on public method's arguments
* but you can use them on the arguments of private methods
* it's alright to use them in the default case of a switch for something you know will never ever happen
* it's not appropiate to modify a class's state from an assertion
OCPJCP 6.0 | OCPJWCD 5 | SpringSource Certified Spring Professional - Spring 3.0