?
Solved

Inner classes

Posted on 2005-03-08
9
Medium Priority
?
306 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
  • 3
  • 3
7 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month8 days, 14 hours left to enroll

621 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