GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  J2EE  >  Java
Go To First  |  Previous Question  |  Next Question 
 Java  |  Question 924 of 928    Print  
Nested and Inner Classes
What is the need of nested and inner classes in Java? Explain where they are useful?


  
Total Answers and Comments: 4 Last Update: August 20, 2009     Asked by: venkatSeeni 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
March 24, 2009 03:20:25   #1  
shabrena Member Since: September 2007   Contribution: 1    

RE: Nested and Inner Classes
In nested class the variable and methods from the outer class can be invoked by the inner class. Whereas the variable and of inner class cannot be invoked by outer class.
 
Is this answer useful? Yes | No
May 01, 2009 12:50:12   #2  
ravi89 Member Since: May 2009   Contribution: 1    

RE: Nested and Inner Classes
The variables and method of inner class can be invoked by outer class.
 
Is this answer useful? Yes | No
May 23, 2009 04:24:10   #3  
msuresh70 Member Since: May 2009   Contribution: 4    

RE: Nested and Inner Classes
Nested class is static class wrapped inside the outer class
Inner class is non-static class wrapped inside the outer class which has access to the instance variables of outer class.

 
Is this answer useful? Yes | No
August 20, 2009 05:04:01   #4  
Sarje Member Since: August 2009   Contribution: 62    

RE: Nested and Inner Classes
Using Inner classes you can write more efficient code and even reduce the typing work. Inner classes are frequently used in Event Handling. For example to MouseEvent event is handled in following example:

import java.applet.*;
import java.awt.event.*;
public class AnonymousInnerClassDemo extends Applet
{
public void init(){
addMouseListener( new MouseAdapter(){
public void mousePressed(MouseEvent me) {
showStatus("mouse pressed");
}
});
}
}

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape