Are static local variables allowed in Java?

Object Oriented ProgrammingJava8Java Programming

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;
raja
Published on 23-Jul-2018 09:15:47
Advertisements