Computer Science, asked by anuj, 1 year ago

What is static variable?

Answers

Answered by AishaSingh1
0
in computer programming, a static variable is a variable that has been allocated "statically", meaning that its lifetime (or "extent") is the entire run of the program......
Answered by Anonymous
2

A static variable is a variable declared by the static keyword . The static variable is a variable which is available as a single copy to be used by all the objects of a class .

A method which is declared with the static keyword is called the static method .

Example of static variable :

class anything

{

static int dead ;

public static void main(String args[])

{

System.out.println(dead);

}

}

Output : 0

Here dead is a static variable because it is declared with the static keyword .

Another example :

class Hitler

{

static double worldwar2 ;

public static void main(String args[])

{

System.out.println(worldwar2);

}

}

Output : 0.0

Here worldwar is a static variable because it is declared with the static keyword .

Similar questions