InterviewSolution
| 1. |
What is static variable? |
|
Answer» 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 . |
|