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

What is the final variable?

939


What is meant by collection in java?

782


What is boolean strategy?

867


What is a java list?

821


How does enum work in java?

775


What is the indent key?

793


Why java is call by value?

776


Can I override protected method in java?

802


Is char * a string?

744


What are user defined exceptions?

803


What are the difference between composition and inheritance in java?

736


What is a map in java?

753


What is preflight request?

731


What is string pool?

823


What are the escape sequences in java?

758