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

0 votes
209 views
Paul Wilson asked 13-Nov-2017 in programming by Paul Wilson

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

1 Answer

0 votes
Arti Mishra answered 12-Aug-2018 by Arti Mishra
“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);
}
}