• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Assertion problem?

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Dan Coo
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ben Ritchie
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Confused me too...
 
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but ben, the typo is args.length>0 will throw assertion error, but the ans is a) contrast, what is exact result,
 
Ben Ritchie
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whoops ... must read before I post...
Edited
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic