Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...


Can you declare a static variable in a method?

Answers were Sorted based on User's Feedback



Can you declare a static variable in a method?..

Answer / 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

Can you declare a static variable in a method?..

Answer / 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

Can you declare a static variable in a method?..

Answer / venkatesh

No we can't declare a static variable in a method.
only final and default scope variables are allowed inside
the method

Is This Answer Correct ?    10 Yes 0 No

Can you declare a static variable in a method?..

Answer / aravinda reddy

No we can't declare a static variable in a method or static
method, static variables are class level variables. Static
means one per class as per OO rules and method level
variables scope is with in the method. So if java allows
static variable inside a method, static concept is useless.

Is This Answer Correct ?    8 Yes 0 No

Can you declare a static variable in a method?..

Answer / ali

No Static Variable cannot declare in method.
but the method present in class can access the static variable
of class.
Or the method which is trying to access the static variable of
class but method is not part of that class at that time declare method as static then it can access that static variable.

Is This Answer Correct ?    1 Yes 0 No

Can you declare a static variable in a method?..

Answer / muthusenthil

No, you can declare static variable only in static method

Is This Answer Correct ?    6 Yes 19 No

Can you declare a static variable in a method?..

Answer / aditya mohata

ya.

Is This Answer Correct ?    3 Yes 28 No

Post New Answer



More Core Java Interview Questions

What is difference between call by value and call by reference?

0 Answers  


What are the methods used to implement for the key object in the hash map?

0 Answers  


What are the two categories of data types in the java programming language?

0 Answers  


What does those terms actually mean included in the j.d.k i.6?

0 Answers  


What is the declaration statement?

0 Answers  






Give few examples of final classes defined in Java API?

0 Answers   BirlaSoft,


Objects or references which of them gets garbage collected?

0 Answers  


What is the base class of all exception classes?

0 Answers  


Explain the difference between transient and volatile in java?

0 Answers  


Do extraneous variables affect validity?

0 Answers  


What are virtual methods?

1 Answers   TCS,


java Api provided try catch finally ,try catch(its ok) but why try finally and exception occured at try then how the flow is?

1 Answers   Naaptol,






Categories