This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach 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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets 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: 37953
    
  22
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.
 
 
subject: Private Accessibility
 
Similar Threads
Number calculations
Interface & Abstract Classes
Applet Troubles
Why use protected???