• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class declaration

 
Vishakha Ahuja
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many books mention that a "Top Level" java class can be public or not public (i.e not declared with any access modifier). What about the modifiers protected and private, can they be used with top level class ?
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope. Top level classes can only be public/default. No other access modifiers permitted....try it out yourself!
Ajith
 
Vishakha Ahuja
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ajith.
 
J. Macha
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about a private static inner class.
a static inner class is considered a top level class and it can be private.
 
Ramesh Donnipadu
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
static inner classes (private or otherwise) are top level nested classes. They are not top level classes.
Top level classes are package level classes with only package as enclosing context.
 
jag_nai
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was nice, Thanks Ramesh!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic