Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static class query

 
Moieen Khatri
Ranch Hand
Posts: 144
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 424
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic