• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

why we cann't make a class private and protected

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to that why we can not declare a class with private and protected modifiers.
 
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Ranch Hand
Posts: 694
Mac OS X Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic