answersLogoWhite

0

Scope of static variables

Updated: 12/17/2022
User Avatar

Wiki User

14y ago

Best Answer

Scope of static variable is with in the file if it is static global.

Scope of static variable is with in the function if variable is declared local to a function.

But the life time is throughout the program

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Scope of static variables
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Which variable is not destroyed on exit from the function instead its value is presented and becomes available again when the function is next called These variables are declared as?

Local function variables defined static remain in memory at all times. Such variables are only in scope (accessible) when the function itself is in scope.


Are static variables serialized in java?

No, static variables are not serialized.


Why static functions cannot use instant variables?

Static functions are tied to a class, not to a particular object. A static function can only access static variables because it has no knowledge of member variables.


Why static variables in a function have global extent?

A variable declared static outside of a function has a scope the of the source file only. It is not a global variable. A variable declared outside of a function and without the static qualifier would be a global variable.


It is perfectly legal to any instance variable inside of a static method?

No. You will get compilation errors. The complier will complain that you are trying to access non static variables from inside a static method. A static method can access only static variables.


How do you access the static variable and static methods of a class?

In java we access static variables and static methods without creating objects. i.e.,we can access directly by using classname we can also access static variables and static methods by using objects which are created by using class where the static variables and static methods are available


Can variables be changed?

A static variable is one which is not stored on the stack but in the memory of the program. Static variables can be changed.


Can non static methods can access static variables?

Yes, they can


Why memory is divided into initialized and uninitialized areas?

The program's data segment. This area of memory is allocated by the linker and is used to store the program's global variables, static variables, static arrays and constants. Constants are always initialised, as are static variables, but global variables and static arrays need not be initialised.


What is automatic storage class specifiers?

Automatic storage is the default storage class for all non-static local variables including formal arguments. All automatic variables are allocated on the call stack and are automatically released when they fall from scope.


Is it possible to write in static variables in main method in java?

Short answer: No. Only class member variables may be declared static. Local variables with a static declaration will throw an error (usually "illegal start of expression").


Are static variable created by giving keyword static in java?

yes bcoz static variables