static Java Keyword

The static is a keyword defined in the java programming language.

static Java Keyword

static Java Keyword

     

The static is a keyword defined in the java programming language. Keywords are basically reserved words which have specific meaning relevant to a compiler in java programming language likewise the static keyword indicates the following : 

 -- The static keyword is applicable to an inner class (a class defined within another class), method or field. 

--  In java language, a static keyword is used with a class (inner) needed to be instantiated, even this may be referenced by some other class indicating as if it - were a top−level class in the class hierarchy.

The example shown below shows how to use static keyword with a class:

public class Class1{

static class Class2;

}

-- A static keyword can also be used with a  field of a class, such a field exists across all the instances of that particular class. 
-- the syntax shown below is used to declare the class constants required to be used from outside the class.

public final static <type> varName = <value>;


Example to use the static keyword with a variable and with a constant:

public class Class1

{

public final static int MAX_OBJECTS = 100;

static int x = 0;

}


-- A static method is invoked even from outside the class without requiring to create the instants of that particular class. We all aware of the use of the " public static void main method()" in most of the console base programming environments.

Example to use the static keyword with a method:

public class Class1{

static int getObjects(){

}
public static void main method(String av[]){

<statements>
<statements>

...

<statements>
}
}