• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

why local classes in a static method?

 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Why are local classes allowed to be declared in a static context, while member inner classes are not allowed to be declared in a static context?
[ April 25, 2003: Message edited by: Marlene Miller ]
 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This may not help at all, since I am a newbie and studying myself. But I've always thought of
public static void main(...)
as a static method. In which case, static methods can only access static class variables or static inner classes (?). As for the inner class, can somebody confirm whether all inner variables (term?) within a static method is treated as a temporary static variable as well? If so then that makes sense, because the inner class within this "main" static method, will be looked as a static class.
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To create an instance of Inner an instance of Test is needed. Just provide it like new Test().new Inner();
Note that within an instance method of Test the implicit this provides the necessary enclosing instance. That is, new Inner(); will compile within an instance method of Test.
[ April 25, 2003: Message edited by: Jose Botella ]
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Inner is like an instance variable of Test. It can only exist in the context of an instance of Test. Think of it this way... Inner has access to all the instance variables of Test. How could Inner have access to them if there was no instance of Test?
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic