aspose file tools*
The moose likes Beginning Java and the fly likes Need: good example of nested top-level class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need: good example of nested top-level class" Watch "Need: good example of nested top-level class" New topic
Author

Need: good example of nested top-level class

Hendrik Reimann
Greenhorn

Joined: Apr 01, 2006
Posts: 4
Hi everyone

I'm looking for a good example for nested top-level class
(like described here: http://www.javaworld.com/javaworld/javaqa/1999-08/01-qa-static2.html)

I mean, i understand how it works, but i don't see any use in it. So a usefull example would be nice.

I found this in my algorithms and datastructures book:

class List {
static class Node {
// Code for Node
}
// Code for the List
}

Hendrik
[ April 02, 2006: Message edited by: Hendrik Reimann ]
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
A couple of examples from the standard library include Rectangle2D.Double and Rectangle2D.Float


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Hendrik Reimann
Greenhorn

Joined: Apr 01, 2006
Posts: 4
Thanx Garrett

If Sun used this technique, then it should make sense.
I don't have time today to look into that, but i'll do that tomorrow.

Hendrik
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
The term 'nested top-level' class is oxymoronic. The very definition of a nested class is any class that is not a top-level class. In other words, the two a mutually exclusive and do not intersect - not only that, they complete the set of "all classes".

You probably want "nested classes".
http://jqa.tmorris.net/GetQAndA.action?qids=67&showAnswers=true


Tony Morris
Java Q&A (FAQ, Trivia)
ak pillai
author
Ranch Hand

Joined: Feb 11, 2006
Posts: 288
From security perspective inner classes are not advised.

http://www.javaworld.com/javaworld/jw-12-1998/jw-12-securityrules.html


Also from a coding perspective the nested classes are hard to read and maintain. Also
very rarely does it get used. If I were you, would not spend too much effort. It is just good to know, how it is done.


java j2ee job interview questions with answers | Learn the core concepts and the key areas
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Need: good example of nested top-level class