• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Nested Class question

 
Esther Kak
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of the two statements is true and why? Can somebody please explain
1. A nested class is any class that is declared within the body of another class or interface.
2. A nested class cannot be declared within the body of another class or interface.

This question is from Question1Dan Chisholm's Certification Questions
 
Charith Fernando
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nested classes are inner classes.... inner classes are declares within a class or an interface... you can declare inner classes inside methods as well...

read about inner classes
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Charith Fernando:
nested classes are inner classes...

Not quite. According to the JLS...

"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." (Ref JLS - 8.)

And...

"An inner class is a nested class that is not explicitly or implicitly declared static." (Ref JLS - 8.1.3.)
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might also be interested in this thread.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic