Can we declare a static variable inside a method?

Can we declare a static variable inside a method?

Hi,

Can we declare a static variable inside a method?

thanks,

View Answers

April 12, 2013 at 10:47 AM

Hi,

The static variable is not attached to a particular object, but rather to the class as a whole. So, the static variable are class level variable and we can't declare inside the method. In case we declare static variable inside the method then it can't compile the program.

For better understanding please visit the link. Hope this will very helpful for you.

http://www.roseindia.net/java/beginners/staticvariable.shtml

Thanks,









Related Tutorials/Questions & Answers:
Can we declare a static variable inside a method?
PHP Static Variable and Methods
Advertisements
cannot declare variable inside @interface or @protocol
Can we replace main() with static block or with other static methods?
Static variable in java
PHP Variable Outside Function
Declare Reference variable
STATIC VARIABLE DECLARATION
Static Variable
Serialize the static variable
Creating a Local Variable in JSP
Creating a Local Variable in JSP
Declare Methods is _jspService() only - JSP-Interview Questions
static methods
how to inherit static variable
static variable in php
can we inherit static method in java?
What is the importance of static variable?
How can we destroy the session, how can we unset the variable of a session?
Application scope variable inside ServletConfigListener
declare a variable that will store an array of 5 objects
static keyword in java
demonstrate a) static data members b) static methods
Example of a class variable (static variable)
Declare tag methods in jsp
How many ways we can pass the variable through the navigation between the pages?
can we use scanner class,class , object and methods to get output without using constructor ????
static functions
Why doesn't Java allow overriding of static methods?
Example of a instance variable
Instance variable in java
non static variable cannot be referenced from static context
non static variable cannot be referenced from static context
Calling Static Methods Using SpEL
static
Use DECLARE Statement in Procedure
why we use constructors instead of methods in java?
Can a class be declared as static?
Java final keyword
static
Java static method example
Can a method inside a Interface be declared as final?
Can a method inside a Interface be declared as final?
PHP Variables Static
Mysql Declare Procedure
javascript where to declare variables
What happen when we write static public void instead of public static void?
methods can be invoked by the container on a stateless session bean
How to declare String array in Java?
JSP methods

Ads