Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Regarding Inner Class

Reply
Thread Tools

Regarding Inner Class

 
 
frank
Guest
Posts: n/a
 
      02-23-2009
Can any One tell When we use the Inner classes?what is its use?
Please Give One Example
Thanks In Advance
 
Reply With Quote
 
 
 
 
blue indigo
Guest
Posts: n/a
 
      02-23-2009
On Sun, 22 Feb 2009 23:22:29 -0800, frank wrote:

> Can any One tell When we use the Inner classes?what is its use?
> Please Give One Example


We're having a five for one special today:

1. Anonymously implement things like ActionListener, Runnable, and the
like, in a method body, approximating having first-class functions.
2. Keep things like ActionListeners, SwingWorkers, and the like internal
to a class instead of breaking encapsulation. For example, a Swing UI
class may contain an inner ActionListener instead of implementing
that interface itself and having to expose a public actionPerformed()
method that will do something bad if someone calls it from outside at a
random time. (It's a shame Sun doesn't seem to know about this use, to
judge by javax.swing.JCheckBox!)
3. Implement things like iterators, sublists, and the like within the
collection class they belong to, where many may need to exist at once
and all are backed by the associated parent collection.
4. Enum constants with behavior (methods specific to the constant) are
implemented as inner (or at least nested) classes of the enum.
5. Implementation classes that are not exposed can be completely hidden
and private, and can also have access to private members of a visible
class, by making them inner classes. LinkedList has an inner Node class
that is not exposed to its users (as well as an inner Iterator class
that is; see item number three). Trees are another case likely to
contain Nodes. This has some overlap with items 2 and 1, keeping
internal ActionListeners and the like internal, with the difference
being that in the one case you need first-class function like behavior
which in Java is had by implementing an interface, which requires a
new class, and in the other (and item 3) you need multiple instances
of the inner objects, which requires a new class, and possibly access
to the enclosing object's private state. (If you don't need such
access, you can also use an external, private class within the same
source file, or an external, default-access class within the same
package, though.)

--
blue indigo
UA Telecom since 1987
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question regarding the inner workings of AurigaDoc omgponies@Usenet-News.net XML 3 04-11-2007 02:11 PM
failing to instantiate an inner class because of order of inner classes Pyenos Python 2 12-27-2006 11:19 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
inner classes in python as inner classes in Java Carlo v. Dango Python 14 10-19-2003 08:49 AM
Static inner class not seeing super class method kishan bisht Java 2 07-02-2003 02:15 PM



Advertisments