An instance is like an entity created by a class. A class is a blueprint, and what is created by a class (blueprint) is called an instance.
As a concrete example, let's say you made a Benz based on a car blueprint. Here, the blueprint of the car is the class and Benz is the instance.
Instance variables are values that are valid only within a particular instance. In addition, there is a class variable as a term that tends to have a mixed meaning with an instance variable. Consider the difference between the two words in the car example above.
Suppose you have "4 tires" and "car shape" on your car's blueprints. The design of "4 tires" is a design that applies to all cars, and it is a common value within the class (in the blueprint). In other words, every car must have four tires.
On the other hand, the "shape of the car" differs depending on the model. Therefore, the shape of the car used in each instance is different, such as this shape when making Benz, this shape when making Prius, and so on. Values that are valid only within each instance are called instance variables.
This article is a transcript of my head to confirm my understanding. It may be wrong, so please point it out.
Recommended Posts