File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Use of static keyword Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Use of static keyword" Watch "Use of static keyword" New topic

Use of static keyword

Neeraj Kumar

Joined: Apr 10, 2003
Posts: 6
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
pinky yadav
Ranch Hand

Joined: Jun 17, 2002
Posts: 44
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

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Use of static keyword