From the first edition of Java 2 Exam Cram, chapter 4, pg 61.
"Classes cannot be protected, private, native, static, or sychronized. The words "abstract" and "final" cannot appear together because an abstract class, by definition, has declared methods that do not have implementations" Doesn't this leave classes to be only public? Why can't you have private classes? What if you don't want developers to use a class as its basically a helper class? (In that case you would probably have it as an inner class right but even in that case I may want to have it be private for encapsulation purposes...I think) Any quick explanation for the class modifiers.
A top-level class can be public or it can have no modifier, in which case only other classes in the same package would have access to it. If a top-level class was allowed to be private, who would be able to access it?
Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Joined: Jul 17, 2002
Originally posted by Ron Newman: A top-level class can be public or it can have no modifier, in which case only other classes in the same package would have access to it. If a top-level class was allowed to be private, who would be able to access it?
I want to say classes within the package but I have this inkling its wrong (private modifier would override the default protected modifier, if one were not given, thus nullifying the package view that no class modifier or the protected modifier gives.) but I can't put my finger on exactly why.
Private means that it can only be accessed by ITSELF . If a top-level class were private then NOBODY could get at it. If you have no access modifier then it is "friendly" or "package" access and only the classes in the same package can access it. This is a valid thing to do.
"JavaRanch, where the deer and the Certified play" - David O'Meara
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com