What is an Object in Programming
Objects in real world are any tangible objects, which you can feel through physical sense like touch, sound or smell. In computer programming, an object is a model of real world object with a state and behavior. State refers to a collection of data about the object and behavior represents any action that can be done by the object or on the object. In code, the state of the object is represented using variables and the behaviors are written either as functions or methods.
Lets take an example of a Bicycle. The state of the bicycle are the color, number of wheels and gears. Behavior on the cycle object would refer to changing gears, applying brakes or pedaling.
What is a Class in Programming
A class is a template that a developer codes, using which objects can be created. An object is called as an instance of an class. Taking the example of bicycle above, lets say a family of four has 4 different bicycles. The father has a mountain bike, whereas the mother has a racing bike, their teenager daughter has a BMX and the toddler has a tricycle. In essence each of the bicycle provided as an example is a distinct object but all of them are bicycles which have a set of common behavior and state. So a class, in layman terms are blueprints for an object. They provide a common structure for a particular object type.
0 comments:
Post a Comment