What is Static Variable

  • Variables that are common to all objects.
  • Fields that have the static modifier in their declaration are called static fields or class variables. They are associated with the class, rather than with any object.
  • Every instance of the class shares a class variable, which is in one fixed location in memory.
  • Any object can change the value of a class variable.
  • class variables can also be manipulated without creating an instance of the class.
  • e.g: If you are going to create a variable serial number for an Item, which is unique for each, you can consider to declare a variable as static because no matter how many instance of class you create, they are also sharing the static variable.
 

dicksonkho

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.