LIWA

Elementary Concept of Objects and Classes

ICSE Class 9 · Computer Applications · Chapter 2

What this chapter covers

Key points

Questions answered

Define an object. What three things does every object have?
An object is a software entity that represents a real-world entity in a program and combines the data describing that entity with the actions it can perform. Every object has an identity, a state and a behaviour.
What is meant by the state of an object? Give an example.
The state of an object is the set of values held by its attributes at a particular moment. For a ceiling fan object, the state "on = true, speed = 3" describes the fan at that moment.
Distinguish between attributes and methods.
Attributes are the characteristics that describe an object and are stored in its variables (data members), such as the balance of an account. Methods are the named blocks of code that express the object's behaviour, such as `deposit()` and `withdraw()`, and they usually read or change the attributes.
Why is a class called a blueprint for objects?
Like an architect's blueprint, a class lays down the design (the attributes and methods) that every object will have, but it is not itself an object. Many separate objects, each with its own values, can be built from one class, just as many houses can be built from one blueprint.
Why is a class called an object factory?
A class can produce any number of similar objects whenever the program needs them. All the objects it produces have the same attributes and methods, but each holds its own values, just as a factory produces many similar items from one design.
What is an instance? How is it related to a class?
An instance is a particular object created from a class, holding its own values for the attributes the class specifies. Every object is an instance of the class from which it was created.
Explain message passing with a real-life example.
Message passing is the way objects communicate: one object asks another to perform one of its methods, giving any values it needs. For example, a remote object sends `changeChannel(5)` to a television object, and the television changes its own channel to 5 without the remote knowing how it does so.
Identify the receiver, the method and the argument in `account.deposit(500);`.
The receiver is the object `account`, the method is `deposit` and the argument is 500. The message asks the account object to add ₹500 to its own balance.