+ 8
What is an 'instance'?
i would need an explanation and example please. thank you.
3 Answers
+ 9
Think of it like this. A class is a "blueprint" for something you want to build in the world. An "instance" is the object that you create with that blueprint. The original blueprint (class) isn't changed or affected by anything that happens to the object you created, and you can use the blueprint (class) to create more of the object as needed. So to summarize, the class is the blueprint for the objects, and each object you create is its own individual instance.
+ 2
The new operator instantiates a class by allocating memory for a new object and returning a reference to that memory. Note: The phrase "instantiating a class" means the same thing as "creating an object." When you create an object, you are creating an "instance" of a class, therefore "instantiating" a class.