aspose file tools*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "static class query" Watch "static class query" New topic
Author

static class query

Moieen Khatri
Ranch Hand

Joined: Nov 27, 2007
Posts: 144
Hi,
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 ]
 
 
subject: static class query
 
Similar Threads
Comparator interface
Object of static class
Searching Arrays and Collections
Comparator interface
Comparator's compare() method question