• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

help on java rule roundup game

 
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?
 
Wanderer
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
 
Life just hasn't been the same since the volcano erupted and now the air is full of tiny ads.
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!