This week's giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Production-Ready Serverless (Operational Best Practices) and have Yan Cui on-line!
See this thread for details.
Win a copy of Production-Ready Serverless (Operational Best Practices) this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Top level Class can be private,protected?  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No.
private and protected access modifiers are not allowed for top level classes.
HTH,
- Manish
 
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1072
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
deezh
Please read the Javaranch Naming Policy and change your publicly displayed name to comply with our unique rule. Thank you for your cooperation.
 
Gold Digger
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
A teeny tiny vulgar attempt to get you to buy our stuff
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!