This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in Access modifiers for classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in Access modifiers for classes" Watch "Doubt in Access modifiers for classes" New topic
Author

Doubt in Access modifiers for classes

Shyam kumar
Ranch Hand

Joined: May 21, 2006
Posts: 146
What are the specifications for defining access specifier for classes. If I have a top level class with default accesbility then how do I know what accessbility can the inner class defined in it can have? Same goes with interface.
I know that we can not define any access specifiers for local classes as they are accessible within the method only. But what about interfaces nested within classes and vice versa. I'm really confused...

Please help...
Matthew Gerald
Greenhorn

Joined: Sep 11, 2006
Posts: 10


This is an example I created because I was not 100% sure as well. It seems the inner class or interface can have any access modifier and still compile.

Edit : Code changed. To extend on this a bit, I also wanted to see scope/instantiation. Test2 will not compile due to interface c being private.
[ October 27, 2006: Message edited by: Matthew Gerald ]

-------------------------<br />SCJP 1.4 10/28/2006<br />SCWCD (next on the list!)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Doubt in Access modifiers for classes
 
Similar Threads
import java.io.*; problem
Reg. Local classes
Why not nesting static classes within a method?
Interface Question
regarding non-static inner class