Why class can not be private in Java?
I'll answer
Earn 20 gold coins for an accepted answer.20
Earn 20 gold coins for an accepted answer.
40more
40more
Works at Facebook, Lives in Menlo Park, CA
A top-level class as private would be completely useless because nothing would have access to it. ... This means that a top level class cannot be private. Private classes are allowed but only as inner or nested classes. If you have a private inner or nested class, then access is restricted to the scope of that outer class.
2023-05-12 12:30:24
评论(499)
Helpful(122)
Helpful
Helpful(2)

Isabella Carter
QuesHub.com delivers expert answers and knowledge to you.
A top-level class as private would be completely useless because nothing would have access to it. ... This means that a top level class cannot be private. Private classes are allowed but only as inner or nested classes. If you have a private inner or nested class, then access is restricted to the scope of that outer class.