• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Inner class

 
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


The class Inner is nested and inner and the class Nested is only nested but not inner?
Am I right?
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic