Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

help on java rule roundup game  RSS feed

 
Nain Hwu
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a new member to java ranch.
Recently I played the Java Rule roundup games and have a question on two questions (#17 and #18):
#17: Can a top-level class be marked as private?
#18: Can a top-level class be marked as protected?
Both answers are "no".

I thought the answer should be "yes", considering that a
nested static class is a also top-level class and is viewed
as a member of the enclosing class. Therefore, it can have
any accessibility modifier that is applicable to a member of
a class, including "protected" or "private".
Am I interpreting the definition "top-level class" incorrectly
in these two questions?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're using an old definition. The JLS2 defines these terms as follows:
A nested class is any class whose declaration occurs within the body of another class or interface. A top level class is a class that is not a nested class.

Since a top-level class cannot be an nested class, the answers are correct.
 
Nain Hwu
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Jim, for clearification. - Nain
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!