Objects in Java: State, Behaviour and Message Passing (ICSE Class 10)
Updated 17 October 2026 · Fact-checked
An object is one real or imaginary thing modelled in a program. Its state is the set of values held in its variables (attributes) and its behaviour is what its methods can do. A class is the blueprint from which objects are made with new. Calling a method on an object, such as b.switchOn(), is called message passing: one object asks another to perform an action.
One class makes many objects, each with its own state; calling b.switchOn() sends a message to the object b only.
Illustration drawn for QuestionBuddy.
Understand Objects: State, Behaviour and Message Passing
Object = state + behaviour. A lamp has a state (on or off, its wattage) and behaviour (it can be switched on or off). In Java the state is stored in member variables (attributes) and the behaviour is written as member methods.
Class = blueprint / factory / new data type. A class describes the variables and methods that every object of that kind will have. It can be seen as a blueprint, as a factory that produces similar objects, or as a new data type defined by the user. The class does not occupy storage for the data; each object created from it does.
Creating an object. Bulb b = new Bulb(); The word new makes a fresh object in memory; the variable b is a reference to it. Each object has its own copy of the instance variables, so two objects of one class can hold different values.
Default values. If you do not give a value, instance variables start with default values: 0 for int, 0.0 for double, false for boolean, null for object references such as String.
Message passing. Computation in an object oriented program happens when objects call each other's methods. b.switchOn() sends the message "switch on" to the object b, and the method decides how to respond. The dot operator joins the object name to the member being used.
Copying a reference is not copying an object. Bulb c = b; gives a second name to the same object. A change made through c is seen through b, because there is still only one object.
A reference without an object. Bulb d = null; is allowed, but d.switchOn(); then causes a run-time error (NullPointerException) because there is no object to receive the message.
Neighbouring topics: how a full class is written is in the chapter "Class as the Basis of All Computation".
Objects: State, Behaviour and Message Passing: key facts
- Object
- Object = state (variables) + behaviour (methods)
- Created by new
- Has its own copy of instance variables
- Identity is separate from state: two objects may hold equal values yet be different objects.
- Creating and using an object
- ClassName ref = new ClassName();
- ref.member
- ref.method(arguments);
- The dot operator reaches members.
- Default values
int 0 double 0.0 boolean false char \u0000 reference types null - Applies to instance variables only; local variables must be assigned before use.
- Class as
- Blueprint
- Object factory
- User-defined data type
- Any one of these in a 1-mark definition.
How to answer Objects: State, Behaviour and Message Passing questions
Use this routine for output questions on objects.
- 1List the objects created with new, and note which reference points to which object.
- 2Write the starting (default) values of each object's variables.
- 3Execute the statements in order, applying each method call to the object named before the dot.
- 4If a reference is copied (b = a), remember both names refer to one object.
- 5Print in the required format, remembering that println ends the line.
Objects: State, Behaviour and Message Passing 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.
Objects from one blueprint with their own state
Suppose a school creates two library cards from one printed template (the class). Each card has the same fields (name, books issued) but different values.
Card A is created and 2 books are issued to it; card B is created and 1 book is issued to it. What are the values of books issued on each card?
Try it first, then show the solutionSolution
- The template is the class; each card is an object with its own books-issued variable.
- Issuing on card A changes only card A: 2. Issuing on card B changes only card B: 1.
Answer: Card A: 2, card B: 1.
Memory hook: One blueprint, many separate objects.
Two names for one object
Imagine a shared notebook which a student calls "my notebook" and her friend calls "Riya's notebook"; both names point to one notebook.
If the friend writes one page through her name, how many pages does the first name see?
Try it first, then show the solutionSolution
- Both names refer to a single notebook, just as two Java references can point to one object.
- A change through either name is visible through both.
Answer: The page written is visible through both names.
Memory hook: Assigning a reference copies the arrow, not the object.
Tricks to remember Objects: State, Behaviour and Message Passing
Short memory aids. Say each one aloud once, then use it on a question the same day.
Nouns and verbs
The nouns an object has (colour, balance) are variables; the verbs it does (switch, deposit) are methods.
Use it when: Splitting a description into state and behaviour.
new = new house
Each new builds a new house from the plan; the plan is the class.
Use it when: Counting objects in output questions.
Arrow copy
b = a copies the arrow, not the house.
Use it when: Reference assignment questions.
Objects: State, Behaviour and Message Passing: solved examples
Ordered from board level to HOTS. Try each one before you open the solution.
Example 1: Attributes and behaviour · 3 marks · Short answerBoard level
A class Student is to model a school student. Name two attributes and two behaviours with their Java forms, and say what the class is.
Try it first, then show the solutionSolution
- Attributes are member variables, for example String name; int marks. (1 mark)
- Behaviours are member methods, for example void display() and double average(). (1 mark)
- The class Student is the blueprint (user-defined data type) from which student objects are created. (1 mark)
Answer: Attributes: name, marks (variables). Behaviours: display(), average() (methods). Student is the blueprint for objects.
Example 2: Two objects, separate state · 3 marks · Short answerHarder board level
Write the output:
class Tally {
int c;
void inc() { c++; }
int get() { return c; }
}
public class Test {
public static void main(String[] args) {
Tally a = new Tally();
Tally b = new Tally();
a.inc();
a.inc();
b.inc();
System.out.println(a.get() + " " + b.get());
}
}Try it first, then show the solutionSolution
- Both objects start with c = 0 (default value). (1 mark)
- a.inc() twice makes a.c equal 2; b.inc() once makes b.c equal 1. (1 mark)
- The expression a.get() + " " + b.get() gives 2, a space and 1. (1 mark)
Answer: 2 1
Example 3: Reference copy · 3 marks · Short answerHarder board level
Write the output:
Tally p = new Tally();
Tally q = p;
q.inc();
q.inc();
p.inc();
System.out.println(p.get() + " " + q.get());(Tally is the class of the previous example.)
Try it first, then show the solutionSolution
- Only one object is created; q = p makes q refer to that same object. (1 mark)
- Three calls to inc() increase its c from 0 to 3, whichever name is used. (1 mark)
- Both p.get() and q.get() return 3. (1 mark)
Answer: 3 3
Example 4: Case study: a bank account · 4 marks · Case-basedHOTS / competency
A programmer writes:
class Account {
double bal;
void deposit(double a) { bal = bal + a; }
double getBal() { return bal; }
}
public class Bank {
public static void main(String[] args) {
Account s = new Account();
s.deposit(500);
s.deposit(250.5);
System.out.println(s.getBal());
}
}(i) Name the class, the object and the reference variable. (1)
(ii) Name the attribute and one behaviour. (1)
(iii) How many messages are passed to s? (1)
(iv) What is printed? (1)
Try it first, then show the solutionSolution
- (i) Class: Account; object: the one created by new Account(); reference variable: s.
- (ii) Attribute: bal; behaviour: deposit() (or getBal()).
- (iii) Messages to s: deposit(500), deposit(250.5), getBal(): three.
- (iv) bal starts at 0.0, then 500.0, then 750.5; the method returns 750.5, printed as 750.5.
Answer: (i) Account, object created by new, s (ii) bal, deposit() (iii) three (iv) 750.5
Example 5: Blueprint, factory, data type · 3 marks · Short answerHarder board level
Explain in your own words three ways in which a class can be viewed. Use the class Bulb as the example. (3 marks)
Try it first, then show the solutionSolution
- Blueprint: Bulb describes the variables (watt, on) and methods (switchOn) every bulb object will have. (1 mark)
- Object factory: each statement new Bulb() produces another bulb object of the same kind. (1 mark)
- User-defined data type: Bulb b; declares a variable of the new type Bulb, which has its own functionality. (1 mark)
Answer: A class is a blueprint, a factory that makes similar objects with new, and a new data type defined by the user.
Where students lose marks in Objects: State, Behaviour and Message Passing
The slips examiners see most often, and what to write instead.
Mistake: Treating a reference copy as a second object
Bulb c = b; creates no new object; both names refer to one object.
Wrong working
c is a separate bulb, so b stays off when c is switched on.
Right working
c and b refer to the same bulb; switching on through c also shows it on through b.
Do this: Count the new keywords: that is the number of objects.
Usually costs: 1 to 2 marks
Mistake: Writing the class name instead of the object name before the dot
Instance members are used through an object, not through the class name.
Wrong working
Tally.inc();
Right working
a.inc(); (a is an object of Tally)
Do this: Create an object first and call the method on it.
Usually costs: 1 mark
Mistake: Forgetting default values
Instance variables not given a value are not blank; numbers are 0.
Wrong working
a.get() before any inc() is not defined.
Right working
a.get() before any inc() returns 0.
Do this: Write the starting values first in every trace.
Usually costs: 1 mark
Exam tips
- Define an object as "state plus behaviour" and map state to variables and behaviour to methods.
- In output questions, write each object's variables in a small table and update it line by line.
- Count the new keywords to find how many objects exist.
- Use real-life examples (a lamp, a bank account) to explain a class; avoid vague words like "thing".
Practice questions on Objects: State, Behaviour and Message Passing
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
How many objects are created by:
Dog a = new Dog(); Dog b = a; Dog c = new Dog();
(a) 1 (b) 2 (c) 3 (d) 0Hint
Count the new keywords.
Answer
(b) 2: only the two new operations create objects; b is another name for the first object.
Q2 · 1 mark · Very short answerBoard level
What is the default value of an uninitialised String instance variable?
Hint
A reference with no object.
Answer
null
Q3 · 2 marks · Short answerHarder board level
Write the output:
class Dog { String name; void bark() { System.out.println(name + " says woof"); } } public class Test { public static void main(String[] args) { Dog d1 = new Dog(); Dog d2 = new Dog(); d1.name = "Tommy"; d2.name = "Rex"; d2.bark(); d1.bark(); } }Hint
Follow the order of the calls, not of the creation.
Answer
Rex says woof
Tommy says woofQ4 · 2 marks · Short answerHarder board level
The following fragment compiles. What kind of error occurs, and when?
Dog d = null; d.bark();Hint
The reference exists; does the object?
Answer
A run-time error (NullPointerException) occurs when the program runs, because d refers to no object, so the message bark() has no receiver.
Q5 · 1 mark · Assertion-reasonHOTS / competency
Assertion (A): Two objects of the same class can hold different values in their instance variables.
Reason (R): Every object created with new gets its own copy of the instance variables.
(a) Both A and R are true and R is the correct explanation of A. (b) Both A and R are true but R is not the correct explanation of A. (c) A is true but R is false. (d) A is false but R is true.Hint
Why can the values differ?
Answer
(a) Both are true and R explains A.
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 is state in an object?Show answer
The values stored in its variables (attributes).
2.What is behaviour in an object?Show answer
The actions it can perform, written as its methods.
3.What is message passing?Show answer
Calling a method on an object so that it performs an action.
4.What is the starting value of an instance variable of type double?Show answer
0.0
5.What does Bulb c = b; do?Show answer
Makes c refer to the same object as b; no new object is created.
6.Which operator joins an object to its method?Show answer
The dot operator.
Objects: State, Behaviour and Message Passing: frequently asked questions
What is the difference between a class and an object?
A class is the blueprint that describes variables and methods; an object is one instance created from it with new, holding its own values.
Does a class use memory for its variables?
Instance variables get memory when an object is created; the class itself is only the description.
Can two objects have the same values?
Yes, but they are still two separate objects with their own copies of the variables.