my dog learned polymorphism
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Can a top level class be private ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Can a top level class be private ?" Watch "Can a top level class be private ?" New topic

Can a top level class be private ?

Rekha Suri

Joined: Mar 22, 2000
Posts: 15
Can a top level class be declared private or protected ? This is from the Round Up game in this site. Any clarification will be helpful.
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Try making one, and see what the compiler will let you.

"I'm not back." - Bill Harding, Twister
Nilesh Parikh
Ranch Hand

Joined: Mar 14, 2000
Posts: 52
the only access modifier that can go with the top level class is public. you can not make the top level class private or protected
Nalini Mistry
Ranch Hand

Joined: Mar 21, 2000
Posts: 64
private and protected cannot be used with classes
Javix Protocol
Ranch Hand

Joined: Mar 21, 2000
Posts: 57
Hey u can use the keywords in methods and variables for the purpose of encapsulation and managing abstraction through that.
But giving the same to a class name suggests that u are reducing ur portability .See whether u can make the keywords in innerclass
since their they might be useful for the encapsulation of class members.Adieu..

Write Once , Run Anytime ,Anywhere Forever And Smile Happily.
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Actually, private and protected may be used as access modifiers for inner or nested classes. Marcus Green's tutorial has been updated to reflect this fact.
I agree. Here's the link:
subject: Can a top level class be private ?
It's not a secret anymore!