File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes default/protected asserts? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "default/protected asserts?" Watch "default/protected asserts?" New topic
Author

default/protected asserts?

Hans Beck�rus
Greenhorn

Joined: Aug 23, 2006
Posts: 24
Hi,
- Do no use assertions to validate arguments to a public method
- Do use assertions to validate arguments to a private method

So far so good when it comes to appropiate use of assert, but what about the "in betweeners", default and protected. Are there any best-practice (official) mentioned somewhere about those two?
I personally would say that protected should be classified as public since you as a programmer can not tell if a class will be sub-classed by a class in another package. When it comes to default access I guess it could be classified as a private method since I guess most commonly you have full control of the current package during development.

Does anyone have any experience about what could be the "correct" definition? Could protected and default be mentioned in the exam
as to their "appropriateness" when it comes to argument validation?
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
I have not seen any offical mention of use of assertions in "default" or protected methods. I do not recall anything in the "Programming for Assertions" document. I tend to agree with your analysis above.

For SCJP I guess it will be always a choice from the two extreme cases: public or private.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Hans Beck�rus
Greenhorn

Joined: Aug 23, 2006
Posts: 24
Originally posted by Barry Gaunt:
For SCJP I guess it will be always a choice from the two extreme cases: public or private.


Thanks Barry, then I will stick with my own "definition" for the other cases. Though, default may be debateble, but I guess thats exactly the
reason for Sun not mentioning anything about them, it may be like telling
someone where to put the brackets
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: default/protected asserts?