• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Static context and local inner classes..

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Annonymous classes are never static even if it's in a static context.
What about the local inner classes in a static method ?
Why static declarations are not allowed in the following ?
I have this:
class Test{
int i;
static void test(){
class Test1{
static int j // This complains..that inner classes
// cannot have static declarations

int k = i; //this complains, as non-static variable
//cannot be accessed from a static context
}
}
}
 
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rekha Rao:
Annonymous classes are never static even if it's in a static context.
What about the local inner classes in a static method ?
Why static declarations are not allowed in the following ?
I have this:
class Test{
int i;
static void test(){
class Test1{
static int j // This complains..that inner classes
// cannot have static declarations

int k = i; //this complains, as non-static variable
//cannot be accessed from a static context
}
}
}


Anonymous class can never be DECLARED static.
But if they are defined inside a static methods then they implicitily become static.
Local class cannot provide class level services even if they are defined inside a static context
"i" is a not static in your case . So referring it inside a static context will create compile time error
HIH
Ragu
 
reply
    Bookmark Topic Watch Topic
  • New Topic