What is the difference between nested classes and inner classes ?

Discussion in 'Java' started by Razvan, Jul 22, 2004.

  1. Razvan

    Razvan Guest

    Hi !




    What is the difference between nested classes and inner classes ?

    Nested is just a synonim for inner ?




    Regards,
    Razvan
     
    Razvan, Jul 22, 2004
    #1
    1. Advertising

  2. "Razvan" <> schrieb im Newsbeitrag
    news:...
    > Hi !
    >
    >
    >
    >
    > What is the difference between nested classes and inner classes ?
    >
    > Nested is just a synonim for inner ?
    >


    Nested classes : embedded top-level classes (static) and inner classes.
    Inner classes : special nested classes which objects need a context
    of an "outer" object.

    Inner classes are: embedded non-static classes, local classes,
    anonymous classes.

    HTH,

    Roman
     
    Roman Seibold, Jul 22, 2004
    #2
    1. Advertising

  3. Razvan

    Roedy Green Guest

    On 22 Jul 2004 06:23:03 -0700, (Razvan) wrote or
    quoted :

    > What is the difference between nested classes and inner classes ?
    >
    > Nested is just a synonim for inner ?


    I think they are just synonyms. Wait for the language lawyer
    responses.

    the big difference in between named and anonymous inner classes.

    The other big difference is between static and instance inner classes.
    statics don't need a mother object.

    See http://mindprod.com/jgloss/innerclasses.html

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Jul 22, 2004
    #3
  4. Razvan

    Dale King Guest

    "Roedy Green" <> wrote in message
    news:...
    > On 22 Jul 2004 06:23:03 -0700, (Razvan) wrote or
    > quoted :
    >
    > > What is the difference between nested classes and inner classes ?
    > >
    > > Nested is just a synonim for inner ?

    >
    > I think they are just synonyms. Wait for the language lawyer
    > responses.
    >
    > the big difference in between named and anonymous inner classes.
    >
    > The other big difference is between static and instance inner classes.
    > statics don't need a mother object.
    >
    > See http://mindprod.com/jgloss/innerclasses.html



    They aren't synonyms, its just that the definitions have changed over time.
    Unfortunately Sun has had to evolve its own confusing and contradictory use
    of the terms. They used to talk about oxymorons like nested top-level
    classes and static inner classes. See this bit I wrote a while back about
    the change in terminology:

    --------------------------------------
    There has been a rethinking in the terminology used for nested classes. The
    old terminology used in the ammendments and clarifications to the original
    JLS is confusing and contradictory. They have cleaned up the terminology in
    the new version of the JLS (which is now released). Here is the new
    terminology, which should be used. Consider the old, confusing terminology
    of nested top-level classes and static inner classes as deprecated.

    - There are top-level classes and nested classes. There is no such thing as
    a nested top-level class. A nested class is simply any class defined within
    another class.

    - Nested classes come in two flavors, static nested classes and inner
    classes. Inner classes have an implicit link to an instance of the class
    they are declared within. They cannot be instantiated apart from an instance
    of their outer class. Static nested classes have no implicit link to an
    instance of the outer class. The term static inner class is now a
    contradiction in terms.

    - Inner classes come in two varieties: named and anonymous.

    --
    Dale King
     
    Dale King, Jul 27, 2004
    #4
  5. Razvan

    Roedy Green Guest

    On Mon, 26 Jul 2004 21:41:32 -0500, "Dale King" <>
    wrote or quoted :

    >- There are top-level classes and nested classes.


    There are two kinds of top-level classes, the first one, for which the
    source file is named, and secondary ones. The rules for each are
    different in terms of public/protected etc.

    Do you have a terminolgy for them?

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Jul 27, 2004
    #5
  6. Razvan

    Dale King Guest

    "Roedy Green" <> wrote in message
    news:...
    > On Mon, 26 Jul 2004 21:41:32 -0500, "Dale King" <>
    > wrote or quoted :
    >
    > >- There are top-level classes and nested classes.

    >
    > There are two kinds of top-level classes, the first one, for which the
    > source file is named, and secondary ones. The rules for each are
    > different in terms of public/protected etc.


    Note, neither can be declared protected. They can only be public or default.

    > Do you have a terminolgy for them?


    No, they are both top-level classes. Any issues about which compilation unit
    you choose to put them in has no real bearing on their properties and does
    not make them a different type of class to warrant a different type of name.
    What compilation unit they were in has no real impact after they are
    compiled.

    So the rules for compilation units is orthogonal to this classification.
    --
    Dale King
     
    Dale King, Jul 27, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jakk
    Replies:
    4
    Views:
    12,229
  2. lonelyplanet999
    Replies:
    1
    Views:
    2,226
    VisionSet
    Nov 13, 2003
  3. Carlo v. Dango
    Replies:
    14
    Views:
    1,037
    Alex Martelli
    Oct 19, 2003
  4. Paul Morrow

    Inheritance and Inner/Nested Classes

    Paul Morrow, Jul 12, 2004, in forum: Python
    Replies:
    10
    Views:
    623
    Peter Hansen
    Jul 12, 2004
  5. Pyenos
    Replies:
    2
    Views:
    389
    Pyenos
    Dec 27, 2006
Loading...

Share This Page