Unlike C/C++, static local variables are not allowed in Java. For example, following Java program fails in compilation with error “Static local variables are not allowed”
class Test { public static void main(String args[]) { System.out.println(fun()); } static int fun() { static int x= 10; //Error: Static local variables are not allowed return x--; } } |
chevron_right
filter_none
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Recommended Posts:
- Static and non static blank final variables in Java
- Final local variables in Java
- Output of Java Programs | Set 45 (static and instance variables)
- Assigning values to static final variables in Java
- Understanding "static" in "public static void main" in Java
- Local Inner Class in Java
- Initialization of local variable in a conditional block in Java
- Local Variable Type Inference or LVTI in Java 10
- Static blocks in Java
- static keyword in java
- Static class in Java
- Static import in Java
- Comparison of static keyword in C++ and Java
- Static vs Dynamic Binding in Java
- Static method in Interface in Java



