This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Private Accessibility Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Private Accessibility" Watch "Private Accessibility" New topic
Author

Private Accessibility

Phillipe Rodrigues
Ranch Hand

Joined: Oct 30, 2007
Posts: 165
Request more explanation on the "Private" accessibility modifier with reference to below example:Why I should get the below error?






Output:

---------- Compile ----------
Sub_class.java:1: modifier private not allowed here
private class Sub_class extends Super_class

1 error

Output completed (1 sec consumed) - Normal Termination


Thanks,
Shiva Kumar Shedad
Greenhorn

Joined: Jun 11, 2007
Posts: 10
First of all a class cannot be made as private whether it extends another class or not...
Because it doesnot make sense...

Originally posted by Phillipe Rodrigues:
Request more explanation on the "Private" accessibility modifier with reference to below example:Why I should get the below error?






Output:

---------- Compile ----------
Sub_class.java:1: modifier private not allowed here
private class Sub_class extends Super_class

1 error

Output completed (1 sec consumed) - Normal Termination
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 43935
    
  33
Classes can actually be private, but I have only seen that inside other classes. If a class isn't inside another class, private access would mean it would be inaccessible to any code from anywhere.
Shiva Kumar Shedad
Greenhorn

Joined: Jun 11, 2007
Posts: 10
Originally posted by Campbell Ritchie:
Classes can actually be private, but I have only seen that inside other classes. If a class isn't inside another class, private access would mean it would be inaccessible to any code from anywhere.


Thanks Ritchie. I had forgotten about the inner classes while replying.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Private Accessibility
 
It's not a secret anymore!