This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static class query

 
Moieen Khatri
Ranch Hand
Posts: 144
  • 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
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic