Iam able to declare & initialise local variable j however when i try to mention a static variable it gives me error. It doesnt give me any error outside the main. Why so ? Since main is mentioned inside a class shouldnt the static variable get associated with the class having the main method ??
Please assist in understanding this.
author and iconoclast
You can't declare static variables inside a method, in main or in any other method. "static" makes sense only for member variables, and variables declared inside a method are local variables, not members.
Java's "static" is unlike the same keyword in "C" in this way -- in C, you can use "static" inside a function -- and so perhaps that's why you're expecting it to work in Java. But it doesn't.