Assertion problem?

Hi all I've come across this question in a mock exam and I can't understand the answer, could somebody help please? public class Assertification { public static void main(String args[]){ assert args.length == 0; } } Which of the following conditions must be true to throw an AssertionError? a) The args array must have exactly zero elements. b) The args array must have one or more elements. The answer is (a), but doesn't that make the condition true. Shouldn't the condition be false to throw an AssertionError?

I've seen this before in Heller & Roberts 1.4 book - is the code fragment a shortened version of that question? The H&R answer is a typo. (edited)the assert will throw an AssertionError only if args.length > 0 so the answer is (b) - it is in the errata on the sybex website [ November 28, 2002: Message edited by: Ben Ritchie ]

SCJP1.4, SCJD, SCEA (in progress)

Dan Coo
Greenhorn

Joined: Nov 10, 2002
Posts: 13

posted Nov 28, 2002 06:52:00

0

Thanks Ben, I've been going over this for days, it is from the Heller and Roberts "Complete Java 2 Certification Study Guide". Thanks again.

It's always best with any technical book to check the errata for the book. This is a pain but it's the 1st thing I usually do with a tech book because so many of them are rushed out and even if they are not it can be very difficult fot the authors/publishers to be 100% correct when so many details are covered. Happy trails