| Author |
Inner class
|
David Ulicny
Ranch Hand
Joined: Aug 04, 2004
Posts: 724
|
|
Hello, what is the exact difference between inner class and nested class? I read the JLS and I'm not sure if I understand it well. Is it that inner class must not be static and nested class must be static ? Thanks for answers.
|
SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
|
 |
Sheldon Fernandes
Ranch Hand
Joined: Aug 18, 2004
Posts: 157
|
|
Below is the terminology used for classes Top Level If a class is not nested, then it is a top level class. Nested Every class declared within the body of another class or interface is known as a nested class. Member If a nested class has a name and is not declared inside of a method, constructor or any block, then it is a member class. Inner If a member class is not static, then it is an inner class. Local If a nested class has a name and is declared inside of a method, constructor or any block, then it is a local class. Anonymous A nested class which does not have a name is an anonymous class. If a nested class does not have a name, then it can not be called a local class even if it is declared inside of a block. Therefore, an anonymous class is never called a local class. Sheldon Fernandes
|
 |
David Ulicny
Ranch Hand
Joined: Aug 04, 2004
Posts: 724
|
|
The class Inner is nested and inner and the class Nested is only nested but not inner? Am I right?
|
 |
Joyce Lee
Ranch Hand
Joined: Jul 11, 2003
Posts: 1392
|
|
David, the Sun tutorial on nested class might help you to clear out the doubt. The class Inner is nested and inner and the class Nested is only nested but not inner? In your example, both the Inner and Nested classes are nested classes. Joyce
|
 |
Peter den Haan
author
Ranch Hand
Joined: Apr 20, 2000
Posts: 3252
|
|
Beware though that some use the terms "nested class" and "inner class" interchangeably - including Sun itself in some of its early publications So always remain on your toes... - Peter
|
 |
 |
|
|
subject: Inner class
|
|
|