aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Top level Class can be private,protected? 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 "Top level Class can be private,protected?" Watch "Top level Class can be private,protected?" New topic
Author

Top level Class can be private,protected?

deezh
Greenhorn

Joined: Jan 29, 2002
Posts: 6
1. package foo;
2.
3. import java.util.Vector;
4.
5. private class MyVector extends Vector {
6. int i = 1;
7. public MyVector() {
8. i = 2;
9. }
10. }
private is valid here?


dizhihui
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2578

No.
private and protected access modifiers are not allowed for top level classes.
HTH,
- Manish
Fisher Daniel
Ranch Hand

Joined: Sep 14, 2001
Posts: 582
Hi,
Access modifier for top level class are only private or no modifier.
But access modifier for inner class are private, no modifier, protected and public.
correct me if i am wrong
daniel
ersin eser
Ranch Hand

Joined: Feb 22, 2001
Posts: 1072
deezh
Please read the Javaranch Naming Policy and change your publicly displayed name to comply with our unique rule. Thank you for your cooperation.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
From JLS 8.1.1 Class Modifiers

Not all modifiers are applicable to all kinds of class declarations. 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. The access modifier static pertains only to member classes (�8.5, �9.5). A compile-time error occurs if the same modifier appears more than once in a class declaration.


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Sam Islam
Greenhorn

Joined: Mar 12, 2002
Posts: 10
Hi Daniel,
The access modifiers for top level classes are either public or default (no modifier).
Static member classes and non-static inner classes can have the following accessibility modifiers: public, protected, private or default.
Hope this helps.
Sam
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Top level Class can be private,protected?