File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes static class query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "static class query" Watch "static class query" New topic

static class query

Moieen Khatri
Ranch Hand

Joined: Nov 27, 2007
Posts: 144
Please can someone explain me this basic concept.I have read about it before but can't recollect now. Why does line 3 gives compilation error if I don't write static in front of ReSortComparator class? Also can someone why we make a class static(advantages)?

Thanks in advance

[ December 26, 2007: Message edited by: Moieen Khatri ]
ahmed yehia
Ranch Hand

Joined: Apr 22, 2006
Posts: 424
If the nested class is non static and you want to use it in the main() which is static, you would need an instance of the enclosing class to instantiate it. Something like this:

Outer.Inner inner = new Outer().new Inner(); // Outer instance is required
[ December 26, 2007: Message edited by: Ahmed Yehia ]
I agree. Here's the link:
subject: static class query
It's not a secret anymore!