Objects may contain data in the form of fields (variables) and methods to operate on that data.
Think about real-world objects around you. What are the characteristics of these objects? Take the example of a light bulb. It has a state, which means that it is either on or off. It also has a behavior, which means that when it is turned on it lights up, and when it is turned off, it does not produce any light. To conclude this, one can say:
Objects are a collection of data and their behaviors.
But where do these objects come from?
The answer to the above question is classes.
A class can be thought of as a blueprint for creating objects.
The illustration below shows what a LightBulb class should look like:
1 of 3
From the above illustration, you can see that the state of the object is generally modeled using variables in a class, and the behavior is modeled using methods.
There can be many different objects of the same class. Each can be in an independent state, but all of them will share the same behavior and characteristics.