Friday, 30 September 2011

object and its features



OBJECT:

An object is an instance of the class. It is an entity that has an existence.

The basic idea behind object oriented language is to combine into a single unit both data and  functions that operate on the data. Such a unit is called an “object”.

For example, a fiat car with registration number AP 09D 3233 is a particular instance of the class cars. It has a unique identity. A car with a different registration number is a different object of the same class cars.

An object fundamentally has three characteristics:

1.      A State
2.      A Behavior
3.      An identity

For example, car is an object of the class cars. Where each car can have the following features:

State: Color, Size, Weight, Engine Capacity etc;
Behavior: Start, Stop, Accelerate etc.
Identity: Registration number etc.

HOW TO CREATE OBJECTS:

class shape
{
private:
int l, b;
public:
void area ()
{
cout<<”area of a rectangle is:” l*b;
}
};

Objects are declared in the similar way how variables are declared.

Shape s1, s2;      //s1 and s2 are objects of type Shape

IMPORTANT FEATURES OF OBJECT:

1.      Each object will be having its own copy of member variables.
2.      But only one copy of member functions is maintained for all the objects of the class.
3.      The size of an object is equal to the sum of the sizes of its member variables.
Member functions add nothing to the size of objects of the Class. Only member variables add to the size of objects of the class.

No comments:

Post a Comment