हिंदी

Different types of Variables

Advertisements

Topics

  • Instance variables 
  • Class variables (Static variables) 
  • Local variables 

Instance variables:

Instance variables are declared within a class but outside methods. They are shared across all objects of the class, referred to as object fields, and hold different values for different objects. 

Class variables (Static variables):

A class variable is declared within the class but outside the member methods along with the static keyword. A variable declared static will be available as a single copy to be used by all the objects of a class. This common field will be affected irrespective of the objects by which it is handled. 

Local variables:

Local variables are declared within a method's body and can't be static. Their scope is limited to the method's curly braces, and they require explicit initialization before use.  

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

Englishहिंदीमराठी


      Forgot password?
Use app×