CHAPTER 2 · COMPUTER APPLICATIONS IX
Elementary Concept of
Objects and Classes
Comprehensive Study Notes — All Topics Covered
Learning Outcomes: After studying this chapter, students will be able to —
• Describe the modelling entities • Explain the use of class and object • Describe message passing
between objects
• Define class as a blueprint • Create a class and its objects
2.1 Introduction to Modelling Entities
All objects in the real world are entities. An entity is something that exists as itself, either in concrete or in
conceptual form. Each entity has some attributes. For example, the 'Furniture' class has different entities
(objects) like bed, cupboard, table, sofa, and chair. Since all these entities have common attributes, they
are grouped into a class.
Object-oriented modelling is a way of thinking about problems using models organised around
real-world concepts. You model entities and their behaviour based on what is relevant to the problem you
are trying to solve and choose the appropriate model.
In object-oriented programming, a program is divided into objects that model real-world entities. Each
object encapsulates data and functions together.
Furniture
(Class) → Bed • Cupboard • Table • Sofa • Chair
2.2 Objects
Objects are the basic unit of object-oriented programming. They are referred to as entities and
identified by distinct names such as flower, chair, book, and so on. Object-oriented programming is a
technique that enables the use of classes and objects to build programs more efficiently. Objects are
created and eventually destroyed — there can be more than one instance of an object, each with its own
specific data.
Three Properties of an Object:
Characteristics State Behaviour
Distinguishing features of the Specifies the current condition of Behavioural properties — what the
object. the object. object can do.
e.g. a pen has ink, a book has an e.g. a pen is completely filled with ink e.g. a pen can be used for writing a
author letter
Types of Objects:
Physical Objects (Real-World) Abstract Objects
• Visible and tangible • Cannot be touched or seen
• Have a definite shape and size • Software is a classic example
• Can be represented in thoughts and figures • State/characteristics of real-world objects become
• Examples: book, pen, bag, car, man data members in software objects
2.3 Class
A class is a collection of objects that share common characteristics and behaviour. It is a logical entity that
does not occupy any space or memory. It provides convenient methods for packing together a group of
logically related data items and functions that work on them.
A class is a non-primitive (user-defined) data type in Java, while an object is an instance of a class. The
terms object and instance are often interchangeable. A class is also called an object factory because it
can produce multiple objects of the same type. A class is a blueprint or template used for creating objects.
Real-Life Examples of Classes and Their Objects:
Class: Human Being Class: Pets Class: Colour
Child • Woman • Man Rabbit • Dog • Cat Blue • Red • Orange
Student Class Diagram (Fig. 2.4):
Class: Student
States (Data Members) Common Behaviours
• Name • Studying
• Age • Dancing
• Colour • Swimming
• Gender
Objects: Ria (Age 12, Fair, Female) · Jay (Age 14, Medium, Male) · Rema (Age 10, Medium, Female). Each object
shares the states and behaviours defined by the class, but holds its own specific values.
Benefits of a Class:
✔ Supports a powerful programming model by encapsulating data and functions into objects.
✔ Increases the reusability of code — common code can be shared among related classes.
✔ The programming interface of an application can be simplified by creating classes.
✔ You can build library classes that other developers can use without any modification.
✔ You can use classes to build tools for various applications.
Difference Between a Class and an Object:
Class Object
A blueprint from which objects are created. An instance of a class.
Has a logical existence. Has a physical identity.
Known as an object factory. Known as an instance of a class.
Declared using the keyword class. Declared using the keyword new.
2.4 Message Passing Between Objects
In terms of computers, message passing is communication between processes. It is a form of
communication used in both object-oriented programming and procedural programming.
In Java, message passing means sending a message from one object to another. A message is a request
to an object to perform an action (behaviour). The key idea: the sending object just sends a message, and
the receiving object decides what to do.
■■■■ Message
Object A Method + Data Object B
Passing ■■■■→
Real-Life Analogy — CS Enterprises:
CS Enterprises (sender) needs employees and contacts SK Placement agency (receiver). CS
Enterprises sends a message — it does not know the internal workings of SK Placement. SK Placement
decides how to find employees. The sender knows only the interface; the implementation is hidden from
it.
2.5 Class as a Blueprint of Objects
In the real world, you often come across individual objects of the same type. A bicycle's blueprint is a
class, and bicycles are instances of the class — i.e., a class is a blueprint from which individual objects
are created.
With one class, you can create several objects of similar kinds. Thus, a class is also referred to as an
object factory. When you create several objects from a class, each object gets unique properties and
exists in the dynamic memory of the computer. Thus, an object is called an instance of a class.
Bicycle 1
instance
Bicycle Bicycle 2
(blueprint / class) → instance
Bicycle 3
instance
House Blueprint Analogy:
A builder has a blueprint of a house. He uses that same blueprint to make as many houses (objects) as
needed. Each house has the same layout but can accommodate a different set of people (different data).
Blueprint = Class | Houses = Objects | People = Data in properties.
2.6 Class as a User-Defined Data Type
A class is a user-defined data type that holds data members and functions (methods) accessible by
creating an instance of that class. A class is also known as a composite data type because it is
composed of member variables of different data types.
Creating a Class in Java:
class Student
// data members
String name;
int g;
// methods
void Marks( ) { ... }
'name' and 'grade' are data members (variables). marks() is a method. Data members have types 'String' and 'int' —
proving a class holds multiple data types, making it a composite/user-defined type.
Defining Objects using the new Operator:
Student s1 = new Student();
Student s2 = new Student();
The new operator allocates memory for each object at run-time. Each object (s1, s2) is an independent
instance of the Student class. Since the class is created by the user, it is called a user-defined data type.
KEY Key Terms
Modelling Entity
Developing or giving a shape to any structure. Anything that has an identifiable body.
Object Class
A unique entity with characteristics and behaviour. A group of objects with common features.
Attribute Method
A data value held by objects in a class. Implementation of an operation by a class.
Data type Instance
Property that defines what type of value a variable can An object created from a class; also called object.
have.
✓ Let's Revise — Quick Summary
→ Objects are the basic unit of object-oriented programming.
→ An object has three properties: characteristics, state, and behaviour.
→ A class is a collection of objects that share common characteristics and behaviour.
→ In Java, message passing means sending a request from one object to another to perform an action.
→ A class is a logical entity that does not occupy any space or memory.
→ A class is a blueprint from which individual objects are created.
→ With one class, you can create several objects of similar kind — hence "object factory".
→ A class is a user-defined (composite) data type.
→ All objects share the attributes and methods described within the class.
→ An object is declared using the keyword new; a class is declared using the keyword class.
KIPS Computer Applications IX · Chapter 2 · Pages 35–46