What are local static variables? and How to use them?

Asked 13-Nov-2017
Viewed 883 times

1 Answer


0

“Static Variable”
Static variables are those variable which is created with the help of static keyword in a class and it is also called class variable. It creates a single copy in the RAM and each object can share it.
Static variable directly accesses by the help of class name without using any objects.

How to Use it
Syntax :      ClassName.VariableName; 

For Example
class Test
{
static int x=100;
Test()
{
System.out.println(“Test Class Call...”);
}
}
class Main
{
public static void main(String args[])
{
Test obj=new Test();
System.out.println(“Value of Static Variable : “+ Test.x);
}
}