aspose file tools*
The moose likes Beginning Java and the fly likes why we cann't make a class private and protected Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "why we cann Watch "why we cann New topic
Author

why we cann't make a class private and protected

Dharmender Singh
Greenhorn

Joined: Jun 14, 2007
Posts: 16
I want to that why we can not declare a class with private and protected modifiers.
Red Smith
Ranch Hand

Joined: Aug 05, 2007
Posts: 136
    
    1
Originally posted by Dharmender Singh:
I want to that why we can not declare a class with private and protected modifiers.


What do you see as the access for a private class:

private class MyClass {

}

what conditions would you have to meet to be able to instantiate objects of this class?

For a protected class

protected class MyProtectedClass {
}

do you want to make a class that cannot be instantiated, but only derived from? I believe that is achieved by declaring a class abstract. Or do you have some other usage for a protected class?
[ August 11, 2007: Message edited by: Red Smith ]
Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 689

I'd like to add my interpretation:

When you use the protected access modifier, it implies that you can also do everything that the private accessor allows, so there is no need to specify both. In fact, as you said in your question, you can't specify both.

Kaydell
[ August 11, 2007: Message edited by: Kaydell Leavitt ]
camilo lopes
Ranch Hand

Joined: Aug 08, 2007
Posts: 202
one class of level top alone is allowed public or default. Now why you would create one class of top of level with these modificadores? I do not see logical in this. These cited modificadores are applied only the members of a classroom.


Brazil - Sun Certified Java Programmer - SCJP 5
http://www.camilolopes.com/ About Java - Update every Week.
Guide SCJP - tips that you need know http://blog.camilolopes.com.br/livrosrevistaspalestras/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why we cann't make a class private and protected