No. A top level class can not be private or protected. It can have either "public" or no modifier. If it does not have a modifier it is supposed to have a default access.If a top level class is declared as private the compiler will complain that the "modifier private is not allowed here". This means that a top level class can not be private. Same is the case with protected.
Makecodeeasy is a blog about programming specially Java. Tutorials written are of core java, servlets, jsp, spring framework and design patterns and other programming language. This helps to refresh programming knowledge, keep updated with latest information, prepare for interview, and certifications.
Saturday, December 1, 2012
Can a top level class be private or protected
No. A top level class can not be private or protected. It can have either "public" or no modifier. If it does not have a modifier it is supposed to have a default access.If a top level class is declared as private the compiler will complain that the "modifier private is not allowed here". This means that a top level class can not be private. Same is the case with protected.
Labels:
class,
Java,
java interview questions,
modifier
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment