what is object?(examples from the real life)

As we have studied about  c++ classes and we found that we use  c++ classes to instantiate objects from it. I know you have a question in mind that what are objects as we are continually using this term. So it is the right time to answer your query.

We can define object as, anything which have some attributes , behaviors and also have a distinct name. Objects are the instantiation of the class.
 As while studying about  c++ class I have given you the example that   a map of  a building is a class because it do not have any physical existence but as contrary to it the building when build will be called an object ,because it has physical existence and if it has physical existence then it have attributes and definite behavior.

Let’s us take another example of object .Consider a  c++ class vehicle which has following attributes and behavior.

Attributes

(1)  Color
(2) Regno
(3) Price
(4) Modal

 Behavior

(1) Brake
(2) Accelerate
(3) Stop
(4) Reverse
 (5) Move

 Now as we know instantiation of class is called object, so we instantiate following objects from  class vehicle

(1) Car
(2) Bus
(3) Truck
(4) Bike

    Now Car, Bus, Truck and Bike are the objects which we instantiate from class Vehicle. As you can see that all the objects have definite name, have definite attributes also they contain definite behaviors. So they fulfill the requirements to be call an object.

  How To Declare Objects?


Objects are declared as class name followed by object name. suppose that our class is vehicle and our objects are Truck, Bus etc.

We can instantiate objects from class Vehicle as

Vehicle truck;
Vehicle  Bus;
Vehicle Car;
Vehicle Bike;

This is how we can write the objects. Now using these objects we can invoke different member functions to manipulate the states of the object.

Note::


          If you have further queries about “concept of objects” you can email me at jawad1647@gmail.com, I will try to solve all your queries and also please don’t hesitate to report mistakes as you know "to err is a human". You can report the errors by sending me a mail at the email address given above.

Post a Comment

0 Comments