Are static local variables allowed in Java?n



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;
karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know


Advertisements