A simple analogy of Java classes, instances, and objects. .. .. [Series that makes you feel like you understand]
Explaining what is different from a class or an instance so that people can imagine it softly
Overview of each
- object
A group of things with state and behavior. Classes are also objects, and instances are also objects.
--Class
A type that collects the common states and behaviors of objects. Design documents.
- instance
The reality generated from the class. The actual situation generated from the design document.
Speaking of cooking
- object
The material. When it comes to cooking, "tuna" or "salmon". In Java, it mainly corresponds to variables and methods. I don't know.
--Class
A recipe. It feels like a recipe death that makes "tuna sashimi" by combining a variable called "tuna" with a method called "cutting". However, it is just a recipe, not "tuna sashimi" itself.
- instance
A dish made from a recipe. It's the "tuna sashimi" itself made from the "tuna sashimi" recipe.