Can you declare a static variable in a method?

Answer Posted / vijayakumar chinnasamy

No static variable cannot be declared within static/non-
static method.

only "final" and "default" allowed within in method for
variable declaration. i.e u cant use
private,protected,public,static within method .it display
the compile time error "Illegal modifier".

Is This Answer Correct ?    11 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is an immutable object? How do you create one in java?

597


What is the string function?

550


Difference between keyword and identifier.

589


Is java code slower than native code?

551


when you will synchronize a piece of your code? : Java thread

527






Why isn’t there operator overloading?

589


Is void a data type in java?

522


What is final variable?

492


Explain access specifiers?

654


How is hashcode calculated in java?

497


What is the difference between length and size in java?

492


What is the purpose of javac exe?

555


Which is better arraylist or vector?

565


When do we use synchronized methods in java?

581


What is main method?

535