OOPortal OOPortal


OO Encapsulation  «Prev  Next»
Lesson 6 What is an object?
Objective Understand how an object relates to a class.

Object Class Concept in C++

An object refers to a location in memory and to the initial value in that memory location. Sounds a lot like a variable, does not it?
In C++ object-oriented programming, the word object refers to a struct or class variable.
That is, a variable of a user-defined type, which has both data values and methods that act on those data values.
When an object is created from a class, it is called an instance of the class.
For example, if we have a class person that contains a data member first_name, then a person object would have some value (such as Laura) in the data member first_name.
We will be looking at classes and objects in much greater detail throughout this course.

In C++, an object is a region of storage with associated semantics. In the context of the object model of C++, the term object refers to an instance of a class.
A class defines the characteristics of its instances in terms of members:
  1. data members (state) and
  2. member functions (methods or operations), and
  3. the visibility of these members to other classes.
C++is statically typed. In C++, an object is a region of storage with associated semantics.
The declaration

int i;

, specifies that the variable i is an object of type int.
In the context of the object model of C++, the term object refers to an instance of a class.
Thus a class defines the behavior of possibly many objects (instances). Objects are usually referred to by references, which are aliases for an object.
The obvious implementation of a reference is as a (constant) pointer that is dereferenced each time it is used.

A C++ class definition generates a user-defined type. A class defines the characteristics of its instances in terms of members:
  1. data members(state) and
  2. member functions (methods or operations), and
  3. the visibility of these members to other classes.

The class defines the form of all objects that belong to that class. Each object of the class that is created receives a copy of all the class data members, except for those declared as static. All objects of a particular class share the member functions for that class.