aspose file tools*
The moose likes Beginning Java and the fly likes Class modifiers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Class modifiers" Watch "Class modifiers" New topic
Author

Class modifiers

Matt Kidd
Ranch Hand

Joined: Jul 17, 2002
Posts: 259
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.
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
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)
Matt Kidd
Ranch Hand

Joined: Jul 17, 2002
Posts: 259
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.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Class modifiers