• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Dan's test ques - Assertions

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://www.danchisholm.net/dec20/topic/section2/assertions1.html


Question 9
Which statements are true?
a. Assertions should not be used to validate arguments passed to public methods.
b. Assertions should not be used to validate arguments passed to nonpublic methods.
c. Assertions should not be used within the default case of a switch statement.
d. Assertions should not be used to perform processing that is required for the normal operation of the application.



answer is a and d.. why not a,b,d ?
can an assertion may used to validate the parameters of a nonpublic method?
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, assertions can be used to validate arguments to non-public methods. Choice 'b' says that you should not do this; therefore, it is *not* true. Since you only select the statements that *are* true, choice 'b' is not a right answer.
 
Ranch Hand
Posts: 937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assertions should not be used to validate arguments passed to public methods True
Because the method gurantess that it will always enforce the argument check. It must check the arguments whether or not assertions are enabled.
Argument checking is typically part of the published specifications of a method. Another problem with using assertions fro argument checking is that erroneous arguments should result in an appropriate runtime exception. An assert failure will not throw an appropriate exception.
Assertions should not be used to validate the arguments passed to non public methods
false
Becuase you know the arguments are true no matter what a client does with teh class
But you can test the post conditions with assertions in both public and nonpublic methods.
post condition: what must be true after a method completes successfully

Assertions should not be used with in the default case of a switch statement
True: or False: ??? Ans according to Dan is Yes, but
Dan says: For example, a programmer may believe that the default case of a switch statement will never be reached. An assertion can be placed in the default case to verify the behavior of the switch statement.

Assertions should not be used to perform processing that is required for the normal operation of the application
True:assertions can be disabled.
 
This parrot is no more. It has ceased to be. Now it's a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic