मराठी

Scope of Variables

Advertisements

Topics

Scope of Variables:

scope of variables refers to the extent of their usage in a program. Basically, a variable is used within the block in which it is declared. Its application outside the block is restricted.  

1. Instance variables:

Instance variables, or data members, are declared within a class but outside methods, accessible in all class methods, and exist as individual copies for each class object until the class ends. The scope is decided by the three access specifiers, public, private and protected. 

2. Class variables:

A class variable, or static data member, declared with the static keyword, is shared among all class objects, unlike non-static instance variables, which are unique to each object. Static members are accessed without object references. 

3. Local variables: 

local variable is a variable that is declared within a function or method. The local variables are used to hold the values temporarily during any operation. Local variables are used only within the scope of a function under which they are declared. The access of local variable outside the function block is not permitted. 

If you would like to contribute notes or other learning material, please submit them using the button below.

Related QuestionsVIEW ALL [1]

Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×