Object State, Behaviour, References and Message Passing in Java with Traces (ICSE Class 9)
Updated 18 October 2026 · Fact-checked
An object has state (the values of its data members), behaviour (its methods) and identity. Objects communicate by message passing, which means calling each other's methods in the form object.method(arguments). Each object keeps its own copy of the data, but a statement like b = a copies only the reference, so both names then refer to one object.
Notice that b and c are two names for one object, so b.fill(10) changes the level seen through both, while a's object stays separate.
Illustration drawn for QuestionBuddy.
Understand Object State, Behaviour, References and Message Passing with Traces
What an object is. An object is a software model of an entity such as a tank, a student or a phone.
- State: the current values of its data members (a tank's level).
- Behaviour: what it can do or what can be done to it, written as methods (fill, use).
- Identity: each object is distinct even when two objects hold equal values.
The methods are the proper way to change the state; this is encapsulation at work.
Message passing. Objects cooperate by sending messages. Sending a message means calling a method of the receiving object: obj.method(arguments). A message names the receiver (obj), the action (method) and any information needed (arguments). In System.out.println("Hi"), the object System.out receives the message println with the argument "Hi". The caller need not know how the work is done (abstraction).
Separate copies of data. Each object made with new has its own data members. Changing a.level does not change b.level.
References. A variable of a class type holds a reference, not the object. Tank c = b; copies the reference, so b and c refer to the same object and a change through one shows through the other. An object that no variable refers to can no longer be used.
class Tank
{
int level;
void fill(int n) { level = level + n; }
void use(int n) { if (n <= level) level = level - n; }
}
Tracing method. Keep one column of values per object (not per variable name). After c = b, put c and b in the same column. After x = y, the old object of x is no longer reachable.
Designing from a description. Nouns describing an entity become data members; verbs become methods.
Neighbouring topics: the class as a blueprint and user-defined type is on the previous page of this chapter.
Object State, Behaviour, References and Message Passing with Traces: key facts
- An object
- State (data members) + behaviour (methods) + identity | instance of a class
- Created with new.
- Message passing
- receiver.method(arguments); | System.out.println("Hi") sends println to System.out
- Receiver, method, arguments.
- Reference copy
- b = a copies the reference
- a and b refer to one object
- change through either shows in both
- No new object is made.
Object State, Behaviour, References and Message Passing with Traces in real life
The idea, met in an everyday situation. Answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.
State and behaviour
Suppose a water tank at home holds 30 litres, you fill it with 20 litres more and later draw 12 litres.
Which part is the state and which is the behaviour? What is the level at the end?
Try it first, then show the solutionSolution
- State: the level of water.
- Behaviour: fill and use.
- Level: 30 + 20 = 50 and then 50 - 12 = 38.
Answer: The level is the state, filling and using are behaviours, and the final level is 38 litres.
Memory hook: State is what it holds; behaviour is what it does.
Message passing
Imagine a customer asks a waiter for a dosa, and the waiter tells the cook.
Describe this as message passing.
Try it first, then show the solutionSolution
- Customer, waiter and cook are objects.
- The request to the waiter is a message with information (one dosa).
- The waiter sends a message to the cook; each object does its own job.
Answer: Each request is a method call on another object, carrying the needed information as arguments.
Memory hook: Objects talk by calling methods.
Tricks to remember Object State, Behaviour, References and Message Passing with Traces
Short memory aids. Say each one aloud once, then use it on a question the same day.
SBI
State, Behaviour, Identity make an object.
Use it when: Features of an object.
Dot means ask
a.fill(20) reads "ask a to fill 20".
Use it when: Message passing.
Copy of a name, not of the thing
c = b copies the name tag, not the tank.
Use it when: Reference traces.
Object State, Behaviour, References and Message Passing with Traces: solved examples
Ordered from board level to HOTS. Try each one before you open the solution.
Example 1: A second name for an object · 1 mark · MCQBoard level
Which statement makes c refer to the same Tank object that b refers to?
(a) Tank c = new Tank(); (b) Tank c = b; (c) Tank c = b.level; (d) Tank c = Tank;
Try it first, then show the solutionSolution
- Only Tank c = b; copies the reference of the existing object.
Answer: (b) Tank c = b;
Example 2: Separate objects · 3 marks · Short answerHarder board level
Using the class Tank above, give the output:
Tank a = new Tank();
Tank b = new Tank();
a.fill(30);
b.fill(10);
a.use(12);
b.use(25);
System.out.println(a.level + " " + b.level);Try it first, then show the solutionSolution
- a: 0 + 30 = 30, then use(12) gives 18. (1 mark)
- b: 0 + 10 = 10; use(25) fails the test 25 <= 10, so b stays 10. (1 mark)
- Output: 18 10. (1 mark)
Answer: 18 10
Example 3: Shared reference · 3 marks · Short answerHarder board level
Continue from the program above and add:
Tank c = b;
c.fill(5);
System.out.println(a.level + " " + b.level + " " + c.level);Give the output of this last line.
Try it first, then show the solutionSolution
- Tank c = b; makes c refer to the same object as b (level 10). (1 mark)
- c.fill(5) changes that object: level 15, seen through b and c. (1 mark)
- a is separate and stays 18: output 18 15 15. (1 mark)
Answer: 18 15 15
Example 4: Case study: reassigning a reference · 4 marks · Case-basedHOTS / competency
A program uses a class Tank as above:
Tank x = new Tank();
x.fill(7);
Tank y = new Tank();
y.fill(20);
x = y;
x.fill(3);
System.out.println(x.level + " " + y.level);(i) State the output. (2)
(ii) What happens to the first Tank object (level 7)? (1)
(iii) Which statement made x and y refer to one object? (1)
Try it first, then show the solutionSolution
- (i) After x = y both refer to the second object (level 20); x.fill(3) makes it 23: output 23 23.
- (ii) No variable refers to it now, so it can no longer be used.
- (iii) x = y;
Answer: (i) 23 23 (ii) it becomes unreachable (iii) x = y;
Example 5: Message passing in a statement · 2 marks · Short answerHarder board level
Identify the receiver, the method and the argument in b.use(25); and explain why it is message passing.
Try it first, then show the solutionSolution
- Receiver: b; method: use; argument: 25. (1 mark)
- The caller asks the object b to perform use with the given information; the object changes its own state. (1 mark)
Answer: Receiver b, method use, argument 25; objects interact only by calling methods.
Where students lose marks in Object State, Behaviour, References and Message Passing with Traces
The slips examiners see most often, and what to write instead.
Mistake: Treating c = b as a copy of the object
Students assume c gets its own copy of the object, as happens when a primitive value is copied. Actually, c = b copies only the reference, so b and c share one object.
Wrong working
Tank c = b; c.fill(5); b stays 10
Right working
Tank c = b; c.fill(5); b becomes 15
Do this: Remember that a class-type variable holds a reference.
Usually costs: 2 marks
Mistake: Calling a method without an object
Methods belong to objects.
Wrong working
fill(20);
Right working
a.fill(20);
Do this: Write object.method().
Usually costs: 1 mark
Mistake: Mixing attributes with behaviours
Nouns and verbs are confused.
Wrong working
Attributes: jump(), score
Right working
Attributes: name, score; behaviours: jump()
Do this: Attributes are what it has; behaviours are what it does.
Usually costs: 1 mark
Exam tips
- Trace with one column per object, not per variable.
- After every assignment of references, note which names now share an object.
- In message passing questions name the receiver, the method and the argument.
- When an if inside a method fails, say the state does not change.
Practice questions on Object State, Behaviour, References and Message Passing with Traces
Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.
Q1 · 1 mark · MCQBoard level
The state of an object is stored in its:
(a) methods (b) data members (c) class name (d) packageHint
State is data.
Answer
(b) data members
Q2 · 2 marks · Very short answerBoard level
Name two attributes and two behaviours of an object "Student".
Hint
Nouns and verbs.
Answer
Attributes: name, roll number (marks). Behaviours: attendClass(), showResult().
Q3 · 2 marks · Short answerHarder board level
Give the output (class Tank as above):
Tank p = new Tank(); Tank q = p; p.fill(8); q.use(3); System.out.println(p.level + " " + q.level);Hint
One object, two names.
Answer
5 5 (p.fill(8) gives level 8; q.use(3) works on the same object: 8 - 3 = 5)
Q4 · 3 marks · Short answerHarder board level
Give the output (class Tank as above):
Tank m = new Tank(); Tank n = new Tank(); m.fill(4); n.fill(4); Tank o = m; o.fill(6); System.out.println(m.level + " " + n.level + " " + o.level);Hint
Which names share an object?
Answer
10 4 10 (m and n are separate objects; o refers to m's object, so fill(6) makes it 10)
Q5 · 3 marks · Short answerHOTS / competency
A garden app describes a plant: "It has a name and a height, and it can grow and be watered." Suggest the data members and methods of a class Plant, and explain why watering one Plant object does not change the height of another.
Hint
Which words are nouns and which are verbs?
Answer
Data members: String name; int height. Methods: grow() and water(). Each Plant object made with new has its own copy of the data members, so a method called on one object changes only that object's height.
Test your recall
Answer in your head or on paper first, then open the card. Pulling an answer out of memory makes it stick far better than re-reading.
1.What are the three features of an object?Show answer
State, behaviour and identity.
2.Which statement copies a reference?Show answer
b = a;
3.What is message passing?Show answer
Objects communicating by calling each other's methods.
4.Where is state stored?Show answer
In the data members.
5.What is a method of an object also called?Show answer
Behaviour.
6.Does each object have its own data members?Show answer
Yes.
Object State, Behaviour, References and Message Passing with Traces: frequently asked questions
Does b = a create a second object?
No. It makes b refer to the same object as a.
Can two objects have the same state?
Yes, but they are still two objects with separate identities.
Is System.out an object?
Yes, the standard output stream object; println is a method called on it.