wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Nested Class question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Nested Class question" Watch "Nested Class question" New topic
Author

Nested Class question

Esther Kak
Ranch Hand

Joined: Oct 11, 2006
Posts: 51
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

Joined: Sep 12, 2005
Posts: 67
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


Charith I Fernando<br />SCJP5, SCWCD, SCBCD, BSc(Hons) IS<br />+94 773 263 222 (mobile)
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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.)


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

You might also be interested in this thread.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Nested Class question
 
Similar Threads
inner class in an Interface declaration
Nested Class
Need your help!
Q from DAN's Nested class exam
Inner class