File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question About Access Specifier

 
Seema Sehgal
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why we cannot declare Base Class to be protected or private?
 
Chengwei Lee
Ranch Hand
Posts: 884
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Think about it, does it make any sense to make your main class private?
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seema,

Welcome to JavaRanch!

We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.

Thanks Pardner! Hope to see you 'round the Ranch!
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why we cannot declare Base Class to be protected or private?

Just in case the reasons weren't becoming clear...

If an outer class were private, then what use would it be since nobody outside the class could access it? It probably wouldn't be very much use since it wouldn't be usable.

If an outer class is declared with default/package access, then other classes in the same package have access to it, while those outside the package wouldn't have access.

If an outer class is declared with protected access, then who has access to it? Well, other classes in the same package would probably have access, but what about classes in a different package? Another classes outside the package couldn't subclass it since it's not accessible outside the package. So, protected would seem like a meaningless access modification.

At least, that's how I'd guess the language designers considered the issue.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic