answersLogoWhite

0

Why static functions cannot use instant variables?

Updated: 8/17/2019
User Avatar

Wiki User

14y ago

Best Answer

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.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why static functions cannot use instant variables?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Can static variables be changed?

No, a static variable means that there is only one copy of that variable, and it is shared by all members of the class, or by all callers of a function.A variable that is read-only would be marked as const or final (depending on language).


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.


Which keyword is used with variables to keep them permanently within the functions?

static


What are global variables in c?

The ones that are declared outside any functions and don't have modifier static.


What types of functions cannot be made virtual?

Static member functions, member function templates and constructors cannot be virtual.


Are static variables serialized in java?

No, static variables are not serialized.


How you declare class scoped variables and member functions?

To scope class members to the class (rather than to instances of the class), declare them as static members of the class. Static members are accessible even when no instances of the class exist. As such, static member functions do not have access to a 'this' pointer, unlike ordinary (nonstatic) member functions.


Can a static method access instance variables?

Variables cannot access variables; only methods can access variables. Non-static methods (also known as instance methods) are local to an object of the class and therefore have access to a "this" reference (referring to the current instance of the class, the object upon which the method was invoked), but static variables are local to the class itself. These variables are shared by all objects of the class and are therefore accessible to non-static methods. Static variable are also accessible to static methods and are therefore accessible even when no objects of the class exist.


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.


What is difference between Static and Global variable?

Static may be local of global -local static variable is limited to the function scope. and retain it's value when function is been called . compiler differentiate static variables with a prefix function name while dealing with same name static variable in different functions. - Global static variable is visible to all the function defined in the file and retain it value but it cannot be used outside this file. now Global Variable --- this variable is also visible to all of the functions inside the file but also can be used outside the file via extern keyword.


Can non static methods can access static variables?

Yes, they can