aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Class declaration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Class declaration" Watch "Class declaration" New topic
Author

Class declaration

Sarath Koiloth Ramath
Ranch Hand

Joined: May 07, 2008
Posts: 52
A file can have more that one nonpublic class.Can we declare a class as protected or private.If not why..?


J 4 Java
Ivan Ivanic
Ranch Hand

Joined: Oct 31, 2007
Posts: 100
Topmost classes (non-inner) can have only public access modifier or non.
Why? Private class wouldn't be accessible by non other. And protected access is quite the same, except subclasses could access it, but what's the use when they can't be accessed by any other class?
[ May 26, 2008: Message edited by: Ivan Ivanic ]

<a href="http://faq.javaranch.com/java/UseRealWords" target="_blank" rel="nofollow">Use Real Words</a> <a href="http://faq.javaranch.com/java/UseCodeTags" target="_blank" rel="nofollow">!!!Use Code Tags!!!</a> <a href="http://faq.javaranch.com/java/SayThanks" target="_blank" rel="nofollow">Say Thanks</a><br />scjp6
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39813
    
  28
You can have protected and private classes, yes, but I think only nested or inner classes.
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

Originally posted by Sarath Koiloth Ramath:
A file can have more that one nonpublic class.Can we declare a class as protected or private.If not why..?


An inner class can be private or protected. I have however found no use for them in the real world.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
 
 
subject: Class declaration