• 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
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Top level class Vs inner classes access specifiers  RSS feed

 
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • 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
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • 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
  • 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
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!