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 do you understand by abstract classes?

826


What is the same as procedures?

747


How do listeners work?

743


Explain the difference between collection api and stream api in java8?

729


What is adapter in java?

712


What are different access specifiers in java? Explain

834


How will you load a specific locale?

734


What is collection class in java?

725


Can a serialized object be transferred via network?

698


Define the term string pool?

788


How do you test a method for an exception using junit?

797


Difference between arraylist and vector.

816


What are the parts of a method?

750


what is nested class in java?

811


What are the advantages of defining packages in java?

737