What is the difference between nested classes and inner classes ?

R

Razvan

Hi !




What is the difference between nested classes and inner classes ?

Nested is just a synonim for inner ?




Regards,
Razvan
 
R

Roman Seibold

Razvan said:
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
 
R

Roedy Green

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
 
D

Dale King

Roedy Green said:
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.
 
R

Roedy Green

- 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?
 
D

Dale King

Roedy Green said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top