• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Nested Class

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which of the following modifiers can be applied to a class that is not a nested class?

a. public
b. protected
c. private
d. abstract
e. static
f. final
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does it say in "Any old Java Book"?

Please edit your topic title because the question is about classes which are not nested classes.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Writing some quick test code might also be informative.
 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Which of the following modifiers can be applied to a class that is not a nested class?



Hi,
A nested class is identified by static modifier. As, you say it is not nested class, you can eliminate the option (e)static. All the remaining options are valid {public, private, protected, final, abstract}.
 
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mani vannan:

"A nested class is identified by static modifier."

:roll:

Originally posted by Mani vannan:
All the remaining options are valid {public, private, protected, final, abstract}.[/QB]



Valid... and that final and abstract can not be together.
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mani vannan:
... A nested class is identified by static modifier. As, you say it is not nested class, you can eliminate the option (e)static. All the remaining options are valid {public, private, protected, final, abstract}.


No.

According to the Java Language Specification, "An inner class is a nested class that is not explicitly or implicitly declared static."

Ref: http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.1.3

So if we know that the class is not nested (as stated in the original question), then it is also not inner. In fact, it is a top level class, as the JLS states, "A top level class is a class that is not a nested class."

Ref: http://java.sun.com/docs/books/jls/third_edition/html/classes.html

Therefore, it is not true that all the remaining modifiers are valid. Per the JLS, "The access modifiers protected and private pertain only to member classes..." and the "access modifier static pertains only to member classes..."

Ref: http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.1.1
[ October 21, 2005: Message edited by: marc weber ]
reply
    Bookmark Topic Watch Topic
  • New Topic