Nested Class, Member Class, Inner Class, Local Class, Anonymous Class

E

E11

Hi,

What is actually the difference between a Nested Class, a Member Class,
an Inner Class, a Local Class, and an Anonymous Class?

This is what i know so far:

A nested class is probably a generic term for all Class declaration
that are not top-level declarations. i.e. so member classes, inner
classes, local classes and anonymous classes are all nested classes. Is
that correct?

An anonymous class doesn't have a formal class name. e.g. we declare an
anonymous class that implements an ActionListener as follows:
ActionListener al = new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
}
}

An inner class, from what i know, is a nested class that is NOT static?

What then is a local class? And what's a member class?



Thanks and Regards,
Edwin
 
T

Thomas Weidenfeller

E11 said:
What is actually the difference between a Nested Class, a Member Class,
an Inner Class, a Local Class, and an Anonymous Class?

Please don't cross post questions. Posting to comp.lang.java.help would
have been enough. F'up set. Also, any good java text book should give
you a detailed answer (homework?).

In short:

* nested (top-level) class:

A class defined as static inside another class. Instances can live
independent of instances of the enclosing class. It's a normal class,
just with a longer name.

* member (inner) class:

A class defined as non-static inside another class. Instances are
dependent on an instance of the enclosing class.

* inner class:

A member, local or anonymous class

* local (inner) class:

Defined inside a code block, only visible inside that code block

* anonymous (inner) class:

A local class without a name.

/Thomas
 

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

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top