• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Top level class Vs inner classes access specifiers

 
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Why top level class cannot be private or protected and inner classes can be private or protected?
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because that is the way it is. What would you do with a top level private class ? Can you even use one ?
 
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
inner classes have most strange concepts that are not applicable to regular class sometimes

like using abstract and static simultaneously (legal)

also other modifiers(private and protected) that applied only to inner class.(legal)
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Arjun Srivastava wrote:
like using abstract and static simultaneously (legal)


Some inner class needs this behavior, but for outer classes, it doesn't make sense!
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Harikrishna

Innerclasses are defined within another class and they are like members of the enclosing class. So just like the members of a class can be private or protected too, innerclasses can also be private or protected, just like methods of a class(because they are members of the class) can use the private members of the class, that is why innerclasses can also access the private members of the class.

One reason for the behaviour shown by innerclasses is because they are members of the enclosing class.
 
reply
    Bookmark Topic Watch Topic
  • New Topic