?
Solved

Inner classes

Posted on 2005-03-08
9
Medium Priority
?
305 Views
Last Modified: 2010-03-31
What is the need of inner classes.
can we manage without inner classes.
0
Comment
Question by:srini_r1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
9 Comments
 
LVL 37

Accepted Solution

by:
zzynx earned 80 total points
ID: 13484905
>> What is the need of inner classes.
It's for quickness of writing.

You can write this:

MyActionListener.java
----------------------------

public class MyActionListener implements ActionListener {

      public MyActionListener() {
      }

      public void actionPerformed(ActionEvent evt) {
          // do what you want to do
      }
}

myButton.addActionListener(new MyActionListener());


Or you can write this (with an inner class):


myButton.addActionListener( new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
          // do what you want to do
      }
});

>> can we manage without inner classes.
Yes
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 30

Expert Comment

by:Mayank S
ID: 13485020
0
 
LVL 35

Expert Comment

by:TimYates
ID: 13485022
>> Or you can write this (with an inner class):

Technically...that's an Anonymous Inner Class ;-)
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 13485035
>> can we manage without inner classes.

Well, in cases where you want an object of the outer class to be created and only then create an object of the inner class for it, then a non-static inner-class is a good choice.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 13485041
Java has a lot of inner classes as well, like javax.swing.JInternalFrame.JDesktopIcon or javax.swing.JPopupMenu.Separator.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month8 days, 22 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question