• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
  • Himai Minh
  • Carey Brown
  • salvin francis

Use of static keyword

Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the following piece of code, "static",a keyword, is used like a function. Yet the compilation succeds and it executes as well.
public class Static
int x=5 ;
static public int x,y ;
public static void main(String[] args)
x-- ;
myMethod() ;
System.out.println(x+y+ ++x);
public static void myMethod()
System.out.println(y = x++ + ++x) ;
However, use of any keyword as identifiers is prohibited.
Can any one explain it why
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the code supplied the static is not the method name. That block of code is a static initializer.
From JLS

Any static initializers declared in a class are executed when the class is initialized and, together with any field initializers (�8.3.2) for class variables, may be used to initialize the class variables of the class.
static Block

You ought to ventilate your mind and let the cobwebs out of it. Use this cup to catch the tiny ads:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic