| Author |
What's the deal with private classes
|
Nithya Natarajan
Ranch Hand
Joined: Feb 25, 2002
Posts: 30
|
|
Hi, I declared a class as private and tried to compile it. It gave me an error: "modifier private not allowed here" Class definition: private class MyClass {} Can anyone please tell me what's wrong in declaring a class as private? Because I thought a class can be declared as private.
|
Thanks<br />Nithya<br />Sun Certified Java 2 Programmer
|
 |
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
|
|
top-level classes cannot be declared private. What would you do with such one? From JLS 8.1.1 Class Modifiers
The access modifier public pertains only to top level classes (�7.6) and to member classes (�8.5, �9.5), and is discussed in �6.6, �8.5 and �9.5. The access modifiers protected and private pertain only to member classes within a directly enclosing class declaration (�8.5) and are discussed in �8.5.1
|
SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
|
 |
Nithya Natarajan
Ranch Hand
Joined: Feb 25, 2002
Posts: 30
|
|
So when a Question is asked such as: which keywords can be used as modifiers in the declaration of method in a class ? and "private" is one of the options, Should I select the "private" option or not?
|
 |
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
|
|
|
private CAN be an access modifier for methods but not for top-level classes, only for inner classes (that is classes enclosed within another class)
|
 |
 |
|
|
subject: What's the deal with private classes
|
|
|