• 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

assertions

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



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.
Answer: G
Can someone explain why ?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please QuoteYourSources.
 
Greenhorn
Posts: 29
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am guessing the source would be a blog with hundreds of question dumped with answers and no explanation!!

@svm muni: If above statement is the case, Please don't trust those blogs/sites, rather trust your book theory and compiler.

By the way for assertions,
1) Do not 'assert' the argument of a "Public" class
2) Do not tend to 'modify' while 'asserting'

Rest is self explainatory, I hope I am not missing any point.
 
Greenhorn
Posts: 21
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Mo-om! You're embarassing me! Can you just read a tiny ad like a normal person?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic