When writing programs, variables are used to store data that can be accessed and manipulated throughout the execution of the code. Three main types of variables serve different purposes. Those variable types are member variables, class variables, and local variables. Understanding the differences between these variable types is important for effectively utilizing them in your programs.
If you don’t have a medium membership, you can use this link to reach the article without a paywall.
Member Variables(Instance Variables)
Member variables, also known as instance variables, are attributes of a class. A class declares member variables within the class but outside of any method. They represent data that is specific to individual objects instantiated from the class. In other words, these variables define the characteristics or properties of objects created from the class.
Unlike local variables (which we’ll discuss shortly), member variables persist as long as the object to which they belong exists. They encapsulate the state of an object…