Model G20 2027 at FLAME University, registrations now open

Elementary Concept of Objects and Classes | ICSE Class 9 Computer Applications Notes

22 min read

On this page

This note covers entities (distinct things to be represented), objects (their representations in a computer program), classes (specifications for objects), attributes (data associated with objects), state (current attribute values), behaviour (actions associated with objects), methods (operations defining behaviour), encapsulation (grouping data with related operations), and message passing (requesting an object's operation).

What is an object, and how does it model an entity?

What does modelling mean?

An entity is something considered as a distinct thing. An employee, student, vehicle, box or book can be represented by an object. Modelling means representing relevant features of such an entity in software, the instructions and associated information used by a computer.

A program is a set of instructions for a computer to carry out a task. Object oriented programming, abbreviated as OOP, organises a program around objects that bring together information and the operations associated with it.

A software object is a representation of an entity, rather than the physical entity itself. Representing a vehicle in a program does not place a physical vehicle inside the computer. It provides a way of describing relevant information and behaviour in software.

Definition: An object is an instance of a class that represents an entity through associated data and behaviour. An instance is a particular object created according to a class specification.

Property: Objects have attributes and methods

The data associated with an object describe its relevant characteristics. These characteristics are called attributes. The operations associated with the object describe its behaviour and are represented by methods. Both sides belong in an explanation of an object.

Modelling requires attention to the task being represented. It does not mean recording every possible fact about a real entity. The model brings together the characteristics and operations needed for that task, so an object's description has a clear purpose.

The examples employee, student, vehicle, box and book show that object modelling can apply to different kinds of entities. A particular student and a particular book represent different entities; the same distinction between information and behaviour can guide the description of either.

To recognise an object in a description, ask what particular entity is represented, what information is associated with it and what operations belong to it. Merely identifying a noun does not complete the model: its data and behaviour still need to be considered.

How do attributes describe an object's state?

How are an attribute and its value different?

An attribute describes an aspect of an object. An attribute value is the actual information recorded for that aspect. The distinction matters because identifying what information an object can hold is different from stating the information it currently holds.

The state of an object is described by the values of its attributes at a particular time. Attribute names identify the characteristics being represented; their values tell us the object's condition. A description of state therefore concerns data, rather than a list of actions.

Rule: Identify attributes as the data associated with an object, and identify state through the values of those attributes. Identify actions separately as behaviour.

An object's state can change when an operation changes its stored data. Changing an attribute value does not, by itself, mean that a different class has been defined. The object can continue to follow the same specification while its state changes.

Why distinguish state from a class specification?

A specification describes the structure and behaviour expected of objects of a class. It identifies the kinds of attributes and methods they have. A particular object's state supplies the values associated with those attributes for that object.

ConceptWhat it describesQuestion it answers
AttributeA characteristic represented as dataWhat information is associated with the object?
Attribute valueThe information held for a characteristicWhat is recorded for that characteristic?
StateThe object's attribute values at a particular timeWhat condition does the stored data describe?
MethodAn operation associated with the objectWhat behaviour is available?

Objects created from the same class follow a common specification, but their attribute values need not be identical. Sharing a description of possible characteristics does not require every object to have the same current information. This is why class membership and state answer different questions.

When reading a description, separate the labels for characteristics from their values. Then collect the values to describe the state. This avoids treating the name of an attribute as though it were the entire condition of the object.

How do methods describe behaviour and support encapsulation?

What is a method?

A method is an operation defined in a class that specifies behaviour. For an object, its methods provide ways of performing the actions associated with it. The word behaviour refers to what the object can do, rather than simply to what information it holds.

To invoke a method means to call it, or request that its operation be performed. A method's definition describes the operation; a method call requests its execution. Execution means carrying out the instructions that define the operation.

A method can use an object's data when performing its task. Some methods change stored data, while others obtain or report information without changing it. A method call therefore does not necessarily imply a change of state.

Definition: Encapsulation brings together data and the methods associated with that data within an object oriented unit. A class defines the grouping, and its objects encapsulate their state.

Why consider data and behaviour together?

Describing an object through attributes alone leaves out its operations. Describing it through methods alone leaves out the data those operations are associated with. Encapsulation connects these parts so that the representation includes both information and functionality.

Functionality means the operations or capabilities something provides. An object's functionality is expressed through its behaviour. Thinking about functionality helps distinguish a passive description of characteristics from a model that also provides operations associated with those characteristics.

When analysing an object, first identify the data that describe it. Then identify the operations associated with that data. Finally, explain how the data and operations belong to the same representation. This gives a fuller account than simply naming an object.

Draw and label

State and behaviour within an object

Draw a box labelled Object. Inside it, label one part State: attribute values and another part Behaviour: methods. The enclosing box shows that the representation brings these related parts together.

The diagram is a conceptual organisation of an object, not a picture of physical computer storage. Its purpose is to keep state and behaviour distinct while showing that both are associated with the same object.

How does a class provide a specification for objects?

Property: A class provides a specification for objects

A class specifies the attributes and methods associated with its objects. The specification provides a common description from which particular objects can be created. It describes what those objects have in common without making them the same individual object.

An instance is a particular object of a class. Instantiation means creating such an instance. The class provides the description used in creation, while the resulting object has the state associated with that particular instance.

Definition: A class is a specification for objects. It brings together the description of their data and the methods that define their behaviour.

The specification answers questions about the structure and capabilities of objects of that class. The object answers questions about a particular instance. These are connected levels of description, but a statement about the class is not automatically a statement about every object's current values.

How does a common description help?

For a student representation, distinguish the general description used to create student objects from a particular student object. The general description belongs to the class level; the particular representation belongs to the object level. No particular student's data are required to understand this distinction.

The same reasoning applies to a vehicle representation. A class describes the relevant characteristics and operations for its objects. A particular vehicle object follows that description, while its current state concerns the attribute values associated with that object.

These examples show the difference between a kind of representation and a particular representation. The distinction does not depend on choosing special names or numerical values. It depends on whether the discussion concerns the common specification or an individual instance.

  1. Identify the kind of entity being represented.
  2. Identify the relevant data and behaviour that its objects need.
  3. Describe these common features through a class specification.
  4. Distinguish each particular object from the specification used to create it.

When explaining the relationship, include both directions: a class specifies its objects, and an object is an instance of a class. This connects the definition of each term to the other without treating them as interchangeable words.

Why may a class be viewed as a blueprint and an object factory?

What does the blueprint comparison explain?

A blueprint is a plan or specification used to guide creation. A class may be regarded as a blueprint to create objects. This comparison highlights the role of the class as a description that guides the creation of particular instances.

The plan and the object created according to it have different roles. The plan describes the common structure and behaviour. The object is a particular instance following that description. Calling a class a blueprint is a way of explaining this relationship.

The comparison is useful when distinguishing the description of attributes from actual attribute values. The common description belongs to the class; the particular values describe an object's state. The blueprint view therefore links the class specification with the objects created from it.

Property: A class can produce similar objects

An object factory is a comparison emphasising the creation of objects from a class. A class may be viewed as a factory that produces similar objects. Here, similar means that the objects follow a common class specification.

Similarity does not require identical attribute values. Objects of the same class can represent different particular entities. Their common specification connects them, while their individual states describe the information associated with each of them.

View of a classMain emphasisConnection with objects
BlueprintA plan or specificationObjects are created according to the description
Object factoryCreation of similar objectsObjects share the class specification
SpecificationCommon attributes and methodsEach object is an instance following that specification

The blueprint and factory comparisons explain different aspects of the same relationship. The blueprint view focuses on what is specified. The factory view focuses on creating objects that follow that specification. Neither comparison means that the objects must share an identical state.

For revision, connect each comparison to its purpose: blueprint with description, factory with creation, and object with instance. These connections are more informative than memorising the comparisons without explaining what they show about the relationship between classes and objects.

How may a class act as a user defined data type?

What is a data type?

A data type identifies the kind of data that can be represented and the operations associated with it. A user defined data type is a type defined by the programmer, the person who writes the program, rather than simply selected as an existing basic type.

A class may also be considered as a new data type created by the user, that has its own functionality. In this context, user refers to the programmer defining the class. It does not mean that someone must enter data whenever the class is described.

The class supplies a description of the data and the methods associated with that data. This is why its role as a type includes functionality. It defines the kind of objects being represented together with the operations associated with those objects.

How do the type and instance fit together?

The class describes the type; an object is a particular instance of that type. A student representation can therefore be considered at the level of its class or at the level of a particular object. These views concern different aspects of the same model.

At the type level, ask what information and behaviour the representation provides. At the instance level, ask which particular object is being discussed and what its current state is. Keeping these questions separate prevents a class description from being confused with particular stored values.

Rule: Link the class with the definition of a type, attributes with the data represented, methods with functionality, and objects with particular instances of the type.

The data type view complements the blueprint and factory views. A blueprint explains the specification, a factory explains creation of similar objects, and a user defined type explains how the representation has its own data and functionality within a program.

These are related descriptions of a class, rather than separate kinds of classes. The same class can be discussed through each view. The useful question is which aspect of the relationship is being explained: specification, object creation or the definition of a type.

How do objects communicate through messages and method calls?

What does message passing mean here?

Computation means carrying out operations to perform a task. In an object oriented description, computation can be understood through message passing or method calls between objects. An object requests an operation associated with another object, which performs the requested behaviour.

A message, in this context, is a request for an object to perform an operation. The receiver is the object to which the request is directed. The caller is the part of the program making the method call.

A method call identifies the operation requested from the receiving object. Where the operation needs information supplied with the request, that information is called an argument. The method uses the information required by its definition when carrying out its task.

A result is an outcome produced by an operation. A method may return a result, change state or perform another specified action. Returning a result means making it available to the caller. Not every method call has the same kind of outcome.

How can an interaction be followed?

  1. Identify the receiving object, so that it is clear whose behaviour is requested.
  2. Identify the method being called, which tells you the operation requested.
  3. Identify any information supplied with the call and relevant state provided in the description.
  4. Follow the method's stated behaviour to determine the resulting action or returned information.

The distinction between method definition and method call is essential. A definition describes what the operation does. A call requests that operation. Knowing that a method exists does not show that it has already been called or that its effects have occurred.

Message passing here concerns interaction in the program. It does not, by itself, mean sending an email or using the internet. The term explains how a request for behaviour connects one part of the object oriented computation with another.

Draw and label

A request between objects

Draw a box labelled Calling object and another labelled Receiving object. Draw an arrow from the caller to the receiver, labelled Method call: request for an operation. The arrow represents the direction of the request.

To explain an interaction clearly, identify the receiver and the requested operation before describing the outcome. A method name without its behaviour does not supply enough information to work out a particular result or a particular change of state.

How can you distinguish classes, objects, state and behaviour?

Which question identifies each concept?

These concepts fit together, but they answer different questions. The class describes the common specification. The object is a particular instance. The object's state concerns its attribute values, while its behaviour concerns the operations available through methods.

ConceptQuestion to askWhat the answer should identify
ClassWhat specification defines the objects?The common description of attributes and methods
ObjectWhich particular instance is represented?An individual object of the class
StateWhat information describes its present condition?The values of its attributes
BehaviourWhat operations are associated with it?The actions defined through methods
Method callWhat operation is being requested?A request to execute a method

A class and an object differ as specification and instance. State and behaviour differ as information and action. A method definition and a method call differ as description and request. Keeping these distinctions separate prevents several common confusions from being combined into one answer.

How should you read a description of an object?

Begin with the entity being represented. Decide whether the description concerns a general specification or a particular instance. Then separate statements about the information held from statements about operations. Finally, identify any actual requests to perform those operations.

When a question gives a description of behaviour, use that description to explain the outcome. Do not assume that every operation changes state, that every call returns information or that objects of the same class have identical attribute values.

The examples employee, student, vehicle, box and book can each be examined using this approach. The relevant distinction is between the representation's data and behaviour, then between its common class specification and its particular objects.

A complete conceptual explanation connects the terms instead of listing them in isolation. An entity is modelled by an object; its class supplies the specification; attributes describe state; methods define behaviour; and method calls request operations during computation.

Use the blueprint, factory and type views to explain the class from different perspectives. Retain the distinction between similar objects and identical states. This keeps the whole account consistent, from modelling an entity to describing interaction between objects.

Glossary

  • Entity — Something considered as a distinct thing that can be represented in a software model.
  • Object — A particular instance of a class, representing an entity through associated data and behaviour.
  • Class — A specification describing the attributes and methods associated with its objects.
  • Attribute — A characteristic represented as data associated with an object in a program.
  • State — The condition of an object described by its attribute values at a particular time.
  • Behaviour — The actions associated with an object and defined through its methods.
  • Method — An operation defined in a class that specifies behaviour associated with its objects.
  • Encapsulation — Bringing together data and the related operations within an object oriented unit.
  • Instance — A particular object created according to the specification provided by a class.
  • Instantiation — The creation of an object according to the specification of its class.
  • Blueprint — A plan or specification, used as a comparison for a class when explaining object creation.
  • Object factory — A comparison emphasising that a class can be used to create similar objects.
  • User defined data type — A type defined by the programmer, with its own representation of data and associated functionality.
  • Message passing — Interaction in which an object is requested to perform an operation through a method call.
  • Method call — A request for the execution of a method associated with the receiving object.

Common errors and misconceptions

  • Misconception: A class and an object are interchangeable terms. Correct: A class provides a specification, while an object is a particular instance created according to that specification.
  • Misconception: State means the operations an object can perform. Correct: State concerns attribute values. Operations belong to behaviour and are represented by methods.
  • Misconception: An object is fully described by listing its data. Correct: An object oriented description brings together data or attributes and behaviour or methods.
  • Misconception: Similar objects must have identical state. Correct: Objects of the same class share a specification, but their attribute values need not be identical.
  • Misconception: Defining a method means it has been called. Correct: The definition describes the operation; a call requests execution of that operation.
  • Misconception: Every method call must change the receiver's state. Correct: The effect depends on the method's behaviour; a method can obtain information without changing stored data.
  • Misconception: Message passing necessarily means internet communication. Correct: Here it describes requests for operations through method calls between objects within an object oriented computation.
  • Misconception: User defined data type means data entered by an end user. Correct: Here it means a type defined by the programmer through a class with its own functionality.

Exam-style questions with model answers

Q1. Define an object and state the two aspects associated with it in object oriented programming. [2 marks]
  1. An object is a particular instance of a class that represents an entity in a program.
  2. Its two associated aspects are data or attributes, describing state, and behaviour or methods, describing operations.
Q2. Distinguish an attribute from a method. [2 marks]
  1. An attribute represents data associated with an object; its value contributes to the object's state.
  2. A method defines an operation associated with the object and therefore describes behaviour rather than stored information.
Q3. Explain the specification, blueprint and factory views of a class. [3 marks]
  1. A class provides a specification describing the attributes and methods associated with its objects, so the objects follow a common description.
  2. A class may be regarded as a blueprint to create objects, emphasising the description or plan used in their creation.
  3. It may be viewed as a factory that produces similar objects, emphasising creation according to a common specification rather than identical attribute values.
Q4. Explain encapsulation using the terms data, state, methods and behaviour. [4 marks]
  1. Data are the information associated with an object and are represented through its attributes.
  2. State is described by the values of those attributes at a particular time.
  3. Methods define the operations associated with the object and therefore specify its behaviour.
  4. Encapsulation brings these related data and operations together within an object oriented unit, connecting the object's state with its available behaviour.
Q5. Explain how a class may be considered a user defined data type, covering the programmer, data, functionality and objects. [4 marks]
  1. The programmer defines the class, so the word user refers to the person defining the type rather than someone entering data.
  2. The class specifies the attributes that describe the data associated with its objects.
  3. It also specifies methods, giving the type its own functionality or associated operations.
  4. Objects are particular instances of the type, following its specification while holding the attribute values that describe their individual states.
Q6. Explain object oriented computation through message passing in five points: the request, receiver, method definition, execution and outcome. Do not assume any particular program or output. [5 marks]
  1. A message represents a request for an object to perform an operation. In this description of computation, the request is expressed through a method call.
  2. The receiver is the object to which the request is directed. Identifying it makes clear whose associated behaviour the caller is requesting.
  3. The method definition specifies the operation to be performed. It describes behaviour, whereas the method call requests that the operation be carried out.
  4. Execution carries out the method's instructions, using the information required by its definition. The supplied request and stated behaviour guide the computation.
  5. The outcome depends on the operation: it may return information, change state or perform another action. No particular output follows without a specified method's behaviour.
Q7. Explain the complete relationship between an entity, an object, a class, state, behaviour and a method call. Give one separate point for each term. [6 marks]
  1. An entity is something considered as a distinct thing. Modelling represents its relevant features in software so that the program can work with that representation.
  2. An object is the particular software representation of an entity. It is an instance that brings together associated data and behaviour.
  3. A class supplies the common specification for its objects. It describes the attributes and methods associated with the instances created from it.
  4. State describes the object's condition through its current attribute values. These values concern the particular object rather than merely the general specification.
  5. Behaviour describes the operations associated with the object. Methods define these operations and provide the functionality connected with its data.
  6. A method call requests execution of an operation. Calls between objects connect their behaviour and allow computation to be described as message passing.
Q8. Objects created from a class follow its common attribute and method specification. Does this require them to have identical attribute values? Explain the distinction between similarity and state. [3 marks]
  1. The objects are similar because they follow the same class specification of attributes and methods.
  2. Each particular object's state is described by the values associated with its attributes at a particular time.
  3. A common specification does not require identical values, so objects can share a class while having different states. Similarity of specification must be distinguished from equality of state.

Key takeaways

  • Objects represent entities through associated data and behaviour, connecting information about an entity with the operations related to it.
  • Attributes describe characteristics as data; the values of those attributes describe the object's state at a particular time.
  • Methods define behaviour, while method calls request execution of the operations those methods describe.
  • A class specifies the attributes and methods of its objects; each particular object is an instance of that class.
  • A class may be regarded as a blueprint to create objects or viewed as a factory that produces similar objects.
  • A class may also be considered a user defined data type with its own functionality, specified by the programmer.
  • Objects of the same class follow a common specification, but their individual attribute values need not be identical.
  • Message passing connects objects through requests for operations; the receiving method's defined behaviour determines the outcome.

Test yourself

What is the difference between a class and an instance?

A class provides a specification; an instance is a particular object created according to that specification.

What describes the state of an object?

The object's attribute values at a particular time describe its state.

How are behaviour and methods connected?

Behaviour consists of the operations associated with an object, and methods define those operations.

What does encapsulation bring together?

Encapsulation brings together data and the related methods within an object oriented unit.

What does the blueprint view of a class emphasise?

It emphasises the class as a plan or specification used to create objects.

Why does the factory view refer to similar objects?

The objects follow a common class specification, although their individual attribute values need not be identical.

Who is the user in user defined data type?

Here the user is the programmer defining a class with its own data description and functionality.

Does defining a method mean that its operation has already been performed?

No. The definition describes the operation, while a call requests execution of that operation.