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 static block?

811


What do you mean by of string::valueof expression in java 8?

762


What is size () in java?

844


How do you make a thread in java?

841


What is the use of parseint in java?

778


Can a serialized object be transferred via network?

716


Does list allow duplicates in java?

709


How do you find the independent variable?

749


What are the advantages and disadvantages of object cloning?

794


What is a layout manager and what are different types of layout managers available in java awt?

967


What is the function of compareto in java?

825


What does yield method of the thread class do?

776


What is difference between word and integer?

817


What is final int?

739


Explain about arraylist?

798