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 can you generate random numbers in java?

575


How do you compare arrays in java?

486


Can we call virtual funciton in a constructor ?

1760


What is the purpose of the finalize() method?

690


Can we override the private methods?

509






What is a Presistent Object?

625


Should a main method be compulsorily declared in all java classes?

520


What is the importance of hashcode() and equals() methods?

568


What is foreach loop in java?

513


Difference between string, stringbuffer and stringbuilder?

558


What is the use of join method?

562


What is n in java?

523


What is use of valueof () in java?

543


What is array sorting in java?

534


What is the purpose of file class?

533