A simplified explanation of an object in object oriented programming
An object is an instance of a given class. That’s the most common statement with respect to objects we come across. “Instance” means a single occurrence or example. And this can be a bit difficult to make sense of in the beginning.
An object is needed in order to use methods and data of a class. Now why is that? can’t we use the methods directly as in C? Why do we need the object? What does instance of a class mean? these are certain questions that tend to pop up while beginning to learn OOPM.
The object helps make the code reusable. The same code can be used separately and independently in each object. When we create an object of a class, a copy of all the methods(functions) and variables in the class is created inside/for the object. That particular copy of the methods and variables is known by the name of the object.
The class is just a blueprint for reference. It just defines the methods and variables.It doesn’t actually run/implement them. For that an object is required. Now consider a blueprint of a car. One can’t actually drive a blueprint. Its just a drawing. Yes it contains doors, steering wheel and an engine but they do not exist in real life as yet. The blueprint is just a paper. You need to build a real car using the blueprint in order to drive it. The car is therefore the object, the blueprint of it is the class. How does this help reusability?
You can create manufacture multiple cars using the same blueprint. All the cars will have the same design but will be different entities nevertheless. Each car has a similar steering wheel and gear box(i.e. data), but each steering and gearbox is a different entity and each car can be driven in a way preferred by the individual. You can make multiple cars out of a single blueprint. Each car can be customized to a certain extent i.e. the owner can install a music system preferred or bring in different seat covers or paint, as long as the structure of the car remains the same, it follows the blueprint. Same is with objects and classes. A certain level of customization is provided to each object, but each object is essentially a copy of the class blueprint.
The object thus created for a certain class is a car created out of a certain blueprint. It will contain all the specifications and qualities the blueprint mentions, for real and not just on paper. And that will be a given example or occurrence of the blueprint in real life. In other words, the car is an instance of the blueprint. i.e. object is an instance of a class.