Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inner Classes

 
Anushkha Rana
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can somebody explain me the naming coventions related to Nested Classes?
Some questions are specific when mentioning whether they are refering to static inner classes or non static inner classes or local classes or anonymous classes. But sometimes the questions simply refer as inner class (which is synonymous to non static inner classes - please correct me if i am wrong). Which one is being referred to in such a case?
Am i right to say that static inner class is also called nested class?
Thanx in advance!!
 
Martin Smith
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I *think* nested is just the general term for any class which is literally nested within something.
I'd say a class is; top-level OR nested
if nested then; member OR method-local OR anon
if member then; static OR non-static (aka inner)
Perhaps some beer swilling cowboy can confirm.
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Martin, I hope you don't mind, I am going to repeat what you just said.
A class is either (1) a top-level class or (2) a nested class.
If a class is a nested class, it is either (1) a member class, (2) a local class or (3) an anonymous class.
Member classes declared in classes are either non-static or explicitly declared static.
Member classes declared in interfaces are implicitly static.
Inner classes include non-static member classes, local classes and anonymous classes.
----
Definition: A nested class is any class whose declaration occurs within the body of another class or interface.
Definition: A top level class is a class that is not a nested class.
Definition: An inner class is a nested class that is not explicitly or implicitly declared static.
----
Beware: Some authors use the word �inner� where the JLS uses the word �nested�.
Beware: Some authors use the terms �top-level nested� and �static inner�. These terms are not consistent with the usage of the JLS.
 
Anushkha Rana
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx guys for the response..
I hope there is no confusion regarding this terminology in the exam
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope there is no confusion regarding this terminology in the exam.
I am not confident that the exam goes strictly by the JLS.
standard terminology on inner classes
Inner classes and 1.4 exam
 
Anushkha Rana
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its really confusing!!
Kathy says in one of the threads

a NON-static inner/nested class could be called any of the following:
* nested class
* inner class
* method-local inner class
* anonymous inner class

However, BruceEckel in TIJ (Topic: Nested classes) says

If you don�t need a connection between the inner class object and the outer class object, then you can make the inner class static. This is commonly called a nested class.

He uses Inner classes the same way as u said:

Inner classes include non-static member classes, local classes and anonymous classes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic