It's not a secret anymore!*
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
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: 38467
    
  23
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: Private Accessibility