Can you declare a static variable in a method?

Answer Posted / murali

No, Static variables can be declared as a class attributes,
for example,
public classA{
static String m2="xyz"; // this is correct form
public static void main(String args[]){
static String m1="abc"; // this gives an error
(illegal modifier for parameter;;....)
}
}

Is This Answer Correct ?    25 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How is final different from finally and finalize?

497


What are different access specifiers in java? Explain

629


What is primitive array?

524


What is a char in java?

539


What are the main uses of the super keyword?

559






Can main() method in java can return any data?

650


Why are variables important in research?

558


when should you use stringbuilder class in a program?

524


How many bytes are there?

544


What is treeset in java collection?

529


What is passing parameters in java?

526


If I don't provide any arguments on the command line, then what will the value stored in the string array passed into the main() method, empty or null?

714


What is the exact difference in between unicast and multicast object? Where we will use?

561


What are the two environment variables that must be set in order to run any java programs?

533


What is meant by nested loop?

546