Are Static Local Variables Allowed in Java?



Unlike C, C++, Java does not allow static local variables. The compiler will throw the compilation error.

Example

Create a java class named Tester.

Tester.java

Live Demo

public class Tester {
   public static void main(String args[]) {
      static int a = 10;
   }
}

Output

Compile and Run the file to verify the result.

Tester.java:3: error: illegal start of expression                
   static int a = 10;
Updated on: 2020-06-18T15:41:40+05:30

994 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements