File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Inner Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Inner Class" Watch "Inner Class" New topic
Author

Inner Class

Fisher Daniel
Ranch Hand

Joined: Sep 14, 2001
Posts: 582
Hi all,
What are differencess between non-static inner class, static inner class, local class and anonymous class
thanks
daniel
Wilfried LAURENT
Ranch Hand

Joined: Jul 13, 2001
Posts: 269
The main difference between static and non-static inner class is that in the first case, you need to have a reference to the outer class if you want to handle the inner class (in case it is public).
Public static inner classes are of interest if you want for example to add a unit testing code to you class.

There are two interesting point: The first one is that the code are generated in two files Toto.class and Toto$TotoTest.class, so that they can be sorted out when deployed. And the second one, is that you only have to call java TotoTest.class to run you unit test.

Non-static Inner classes are often used for "inner use", as for listener implementation for example.

With such a way to proceed the class and the listeners are tighly coupled (which may or may not be advantageous).
You could also have used an anonymous class if you do not feel the need to create more instances of MyActionListener. The class implementation is directly given as method argument.

Hope this helps.
W.
[This message has been edited by Wilfried LAURENT (edited September 28, 2001).]
[This message has been edited by Cindy Glass (edited September 28, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inner Class