Object-orientated languages

Procedural languages rely on the process of passing data from one procedure to another. Procedures and the code within them exist independently of the data. They simply access data deemed relevant by the programmer as and when necessary. The data used is separate from the code.

However, object-oriented languages treat data and code as part of the same object. Firstly a class is created. A class acts as a template for an object and classes are examined in more detail later in this section. Objects are created within a class and will contain code and the data that the code requires. Data and code is not held separately. The name given to the concept of an object containing both the code and its related data is called 'encapsulation'.

Procedural language: Parameters get passed between procedures. Object-oriented: objects encapsulate both code and data. Objects interact with one another.

In our world there are many objects such as cars, boats, buses, doors etc. To think of objects in this way is a good starting point. An object such as a train will have a set of attributes.

When working with object-oriented languages there are a number of different terms used that mean the same thing. To avoid confusion the following reference is helpful:


When describing objects it is common to make reference to attributes. Attributes describe an object. Attributes are sometimes called fields or instance variables.


The term 'state' describes the value of an attribute/instance variable at any given time. The following example shows different attributes for an object, in this case a train. At any point in time the attributes will have a state. The state of an attribute is simply its current value.

Attribute/Instance variableState
Power sourceCoal
Maximum speed80mph