Java Objects: State, Behaviour and the JVM (ISC Class 11 Computer Science)
Updated 17 October 2026 · Fact-checked
An object combines data (state, held in instance variables) with behaviour (methods) and has an identity; a class is its blueprint. Objects interact by calling each other's methods, and a method call can change the state of the object it is called on. A Java program is compiled to bytecode that the Java Virtual Machine (JVM) runs, which makes the same program portable across platforms.
Notice that calling next() changes the object's state (d and m) while its behaviour, the next() method, stays the same.
Illustration drawn for QuestionBuddy.
Understand Objects: State, Behaviour, Real-world Examples and the Java Virtual Machine
Object = data + behaviour. *State* is the set of values of the object's attributes at a time; *behaviour* is what the object can do (its methods); *identity* distinguishes it from other objects even if the state is identical. A class describes the attributes and methods; objects are created from it with new.
Real-world example: a Date object.
class Date {
int d, m, y;
int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // non-leap year
Date(int d, int m, int y) { this.d = d; this.m = m; this.y = y; }
void next() {
d++;
if (d > days[m - 1]) { d = 1; m++; }
if (m > 12) { m = 1; y++; }
}
}For new Date(28, 2, 2025) the call next() changes the state to 1 March 2025.
Real-world example: a Calculator. The state is the accumulated value; the methods change it. *Changing behaviour:* the same message (a call) gives different results depending on the object's current state and arguments.
class Calculator { double acc;
void add(double x) { acc += x; }
void mul(double x) { acc *= x; } }After c.add(5); c.mul(3); c.add(2); the value of acc is 17.0.
Messages. An object requests a service from another by calling its method (the message); the receiver decides how to respond.
Java Virtual Machine (JVM). javac compiles a program into bytecode (.class). The JVM, a software machine specific to each platform, loads the bytecode, checks it and runs it by interpreting or compiling it on the fly. Hence "write once, run anywhere": only the JVM is platform-specific. The JVM also provides memory management (garbage collection) and security checks.
Objects: State, Behaviour, Real-world Examples and the Java Virtual Machine: key facts
- Object
- Object = State (attributes) + Behaviour (methods) + Identity | Created by new
- Definition.
- Compile and run
- Source file (.java)
- compiled by javac to bytecode (.class)
- run by the JVM on the machine
- Portability.
- Message
- obj.method(arguments) | A request to an object
- Interaction.
How to answer Objects: State, Behaviour, Real-world Examples and the Java Virtual Machine questions
Track the state of each object after every call.
- 1List the attributes and their initial values.
- 2For each call, apply the method to that object's state.
- 3Write the state after each call.
- 4Remember objects of the same class do not share instance variables.
Objects: State, Behaviour, Real-world Examples and the Java Virtual Machine 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 changes
Suppose a Calculator object starts at 0, then receives add(5), mul(3) and add(2).
What is its state after each message?
Try it first, then show the solutionSolution
- After add(5): 5.0.
- After mul(3): 15.0.
- After add(2): 17.0.
Answer: 5.0, 15.0 and 17.0.
Memory hook: Each message moves the object to a new state.
Tricks to remember Objects: State, Behaviour, Real-world Examples and the Java Virtual Machine
Short memory aids. Say each one aloud once, then use it on a question the same day.
State, behaviour, identity
What it has, what it does, which one it is.
Use it when: Object.
Bytecode travels, JVM runs
Portability comes from the JVM.
Use it when: JVM.
Message = method call
Objects talk by calling methods.
Use it when: Interaction.
Objects: State, Behaviour, Real-world Examples and the Java Virtual Machine: solved examples
Ordered from board level to HOTS. Try each one before you open the solution.
Example 1: Object · 1 mark · MCQBoard level
The values held in the instance variables of an object at a given moment are its:
(a) behaviour (b) state (c) identity (d) class
Try it first, then show the solutionSolution
- The current values of attributes are the state.
Answer: (b) state
Example 2: Class vs object · 3 marks · Short answerBoard level
Explain, with the example of a Calculator, what are the state and behaviour of an object and how a class differs from an object. (3 marks)
Try it first, then show the solutionSolution
- State: the accumulated value acc.
- Behaviour: add() and mul().
- The class Calculator is the blueprint; c = new Calculator() is one object with its own acc.
Answer: State is the value of acc; behaviour is add() and mul(); the class is the blueprint and each calculator created with new is an object with its own state.
Example 3: Trace the Date object · 5 marks · Long answerHarder board level
Using the Date class, give the state after each call: Date a = new Date(28, 2, 2025); a.next(); a.next(); then Date b = new Date(31, 12, 2025); b.next(); and state whether a and b affect each other. (5 marks)
Try it first, then show the solutionSolution
- a starts 28/2/2025: next() makes d = 29 > 28, so d = 1, m = 3: 1/3/2025.
- Second next(): d = 2: 2/3/2025.
- b starts 31/12/2025: d = 32 > 31 so d = 1, m = 13 > 12 so m = 1, y = 2026: 1/1/2026.
- a and b are separate objects: no effect on each other.
Answer: a: 1/3/2025 then 2/3/2025; b: 1/1/2026; the objects are independent.
Example 4: Calculator output · 3 marks · Short answerHarder board level
Write the output: Calculator c = new Calculator(); c.add(5); c.mul(3); System.out.print(c.acc + " "); Calculator e = new Calculator(); e.add(2); System.out.println(e.acc + " " + c.acc); (3 marks)
Try it first, then show the solutionSolution
- c: acc = 5.0 then 15.0.
- First print: "15.0 " (print without a new line).
- e: acc = 2.0; then println prints 2.0 and c.acc = 15.0.
Answer: 15.0 2.0 15.0
Example 5: Portability · 4 marks · Short answerHOTS / competency
A software company ships the same .class file to customers using three different operating systems. Explain with the JVM why this works, what must the customers install, and why a C program compiled for one system would not work on the others. (4 marks)
Try it first, then show the solutionSolution
- The .class file holds bytecode, not machine code.
- Each customer installs a JVM for their own operating system, and the JVM runs the bytecode.
- A compiled C program contains machine code for one processor and operating system; it cannot run on the others without recompiling.
- Only the JVM is platform-specific.
Answer: Bytecode is run by the JVM installed on each system, so the same file works everywhere; machine code from C is tied to one platform.
Where students lose marks in Objects: State, Behaviour, Real-world Examples and the Java Virtual Machine
The slips examiners see most often, and what to write instead.
Mistake: Treating a class as an object
Mixing blueprint and instance.
Wrong working
Calculator is an object
Right working
Calculator is a class; c is an object
Do this: Class = type; object = instance.
Usually costs: 1 mark.
Mistake: Sharing state across objects
Assuming one copy.
Wrong working
e.acc becomes 17.0
Right working
e.acc is its own value
Do this: Each object has its own state.
Usually costs: 2 marks.
Mistake: Saying the JVM compiles source code
Confusion with javac.
Wrong working
JVM compiles .java
Right working
javac compiles; the JVM runs bytecode
Do this: Separate the two.
Usually costs: 1 mark.
Exam tips
- Give state and behaviour for the example in the question.
- Trace one object at a time.
- Mention bytecode and the JVM in portability answers.
Practice questions on Objects: State, Behaviour, Real-world Examples and the Java Virtual Machine
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 Java compiler converts source code into:
(a) machine code (b) bytecode (c) assembly (d) HTMLHint
JVM input.
Answer
(b) bytecode
Q2 · 2 marks · Short answerBoard level
Identify the state and the behaviour of a Bank Account object. (2 marks)
Hint
Attributes and methods.
Answer
State: account number, holder name, balance. Behaviour: deposit(), withdraw(), displayBalance().
Q3 · 4 marks · Short answerHarder board level
Give the state of a Date object after: Date t = new Date(30, 4, 2025); t.next(); t.next(); (use the Date class above; April has 30 days). Then for Date u = new Date(28, 2, 2025) state the date after three calls. (4 marks)
Hint
days[3] = 30.
Answer
t: 30/4 becomes 1/5 then 2/5/2025. u: 28/2 becomes 1/3, 2/3, 3/3/2025.
Q4 · 3 marks · Short answerHarder board level
A class Counter has int n; void inc() { n++; } void dec() { n--; } and a method reset(). Trace: Counter p = new Counter(); Counter q = new Counter(); p.inc(); p.inc(); q.dec(); p.dec(); System.out.println(p.n + " " + q.n); (3 marks)
Hint
Separate states.
Answer
p.n: 0 to 1 to 2 to 1; q.n: 0 to -1. Output: 1 -1
Q5 · 3 marks · Short answerHOTS / competency
Two Calculator objects c1 and c2 are created, and c2 is assigned to c1 with c1 = c2; Then c1.add(10) is called and acc values are printed. Explain the output and the fate of the first c1 object. (3 marks)
Hint
References.
Answer
After c1 = c2 both names refer to the same object, so c1.add(10) changes the one object: c1.acc and c2.acc both show 10.0 (if c2 started at 0). The original c1 object has no reference left and becomes eligible for garbage collection.
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.Object has?Show answer
State, behaviour, identity.
2.Behaviour is defined by?Show answer
Methods.
3.javac output?Show answer
Bytecode.
4.JVM role?Show answer
Runs bytecode.
5.Is state shared between objects?Show answer
No, each has its own.
Objects: State, Behaviour, Real-world Examples and the Java Virtual Machine: frequently asked questions
Can two objects have equal state?
Yes, but they are different objects.
What is garbage collection?
Freeing memory of unreachable objects.
Is the JVM hardware?
No, software.
What is identity?
What makes an object unique.