User-defined Methods: Parameters, Return Values and Call by Value (ICSE Class 10 Java)
Updated 17 October 2026 · Fact-checked
A method is written once as a header (return type, name, formal parameters) and a body, and called many times with actual parameters. Primitive arguments are passed by value: the method works on copies, so the caller's variables do not change. A pure method only returns a value; an impure method changes the state of an object or a variable outside itself. Call by reference passes the address of an object, so changes to the object are seen by the caller.
Notice that only a copy of 5 enters the method, so changing x to 8 never changes the caller's a.
Illustration drawn for QuestionBuddy.
Understand Calling Methods, Parameters, Call by Value and Pure/Impure Methods
Syntax.
accessSpecifier [static] returnType name(type formal1, type formal2) {
body
return value; // omitted when returnType is void
}The first line is the method header; name(type1, type2) with the types is the signature/prototype.
Parameters. *Formal parameters* are the variables in the header; they receive values. *Actual parameters (arguments)* are the values or expressions in the call: in int r = add(a, 5); the actuals are a and 5. The actuals must match the formals in number, order and (compatible) type.
Return. A method with a return type must return a value of that type; void returns nothing. return ends the method at once.
Static and non-static. A static method belongs to the class and can be called from main (also static) directly by name: sq(4). A non-static method needs an object: obj.method().
Pure and impure. A pure method does not change the data members or its arguments; it only computes and returns. An impure method changes the state of the object (a data member) or changes the object passed to it.
Call by value. When arguments of primitive type are passed, the formal parameter gets a copy of the value. Changes to the formal parameter are lost when the method ends, so the caller's variable stays the same.
Call by reference (definition with example). When an object is passed, the formal parameter refers to the same object as the actual parameter, so changes made through it affect the caller's object. For example, a method that does p.v += 10; on a Num object passed to it changes the original object. (In the syllabus, programs are asked for call by value; for reference only the definition and an example.)
Modular programming. Break a program into several methods with different names, each doing one job, and call them from main.
Calling Methods, Parameters, Call by Value and Pure/Impure Methods: key facts
- Method parts
- Header: specifier, return type, name, formal parameters
- Body
- return statement
- void: no return value
- The prototype/signature is the name with parameter types.
- Actual vs formal parameters
- Actual: in the call, values passed
- Formal: in the header, receive the values
- Match in number, order and type
- Names can differ.
- Call by value
- Formal parameter is a copy
- Change inside does not affect the caller
- Used for primitive arguments
- A swap method on two ints will not swap the caller's variables.
- Pure vs impure
- Pure: returns a value, changes nothing | Impure: changes an object or a data member
- An impure method may be void.
How to answer Calling Methods, Parameters, Call by Value and Pure/Impure Methods questions
Use this routine for method trace questions.
- 1Start from main; note the values of its variables.
- 2At each call, copy the values of the actual parameters into the formal parameters.
- 3Execute the method body with its own variables and stop at return or at the end.
- 4Bring the returned value (if any) back to the place of the call and use it in the expression.
- 5Update the caller's variables only for returned values or for objects changed in the method; primitive arguments never change.
Calling Methods, Parameters, Call by Value and Pure/Impure Methods 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.
Call by value as a photocopy
Suppose a student gives the teacher a photocopy of her answer sheet and the teacher scribbles marks on the photocopy.
Does the original sheet change? How does this relate to passing int arguments?
Try it first, then show the solutionSolution
- The teacher worked on a copy, so the original is unchanged.
- A method receiving an int gets a copy of its value in the same way.
Answer: The original stays the same, like the caller's variable in call by value.
Memory hook: Copy in, nothing out.
Tricks to remember Calling Methods, Parameters, Call by Value and Pure/Impure Methods
Short memory aids. Say each one aloud once, then use it on a question the same day.
Actual = Arrives, Formal = Form
Actual values arrive at the call; formal parameters are the form (slots) in the header.
Use it when: Actual vs formal.
Void has no return
void = empty hands; any other type must return something.
Use it when: Header questions.
Primitives are photocopies
Primitive arguments are copied; objects are shared.
Use it when: Call by value vs reference.
Calling Methods, Parameters, Call by Value and Pure/Impure Methods: solved examples
Ordered from board level to HOTS. Try each one before you open the solution.
Example 1: Actual and formal parameters · 3 marks · Short answerBoard level
In the code below name the actual parameters, the formal parameters and the return type.
static int add(int x, int y) {
return x + y;
}
// call in main:
int r = add(a, 5);Try it first, then show the solutionSolution
- Actual parameters: a and 5, written in the call. (1 mark)
- Formal parameters: x and y, written in the header. (1 mark)
- Return type: int. (1 mark)
Answer: Actual: a, 5. Formal: x, y. Return type: int.
Example 2: Call by value · 2 marks · Short answerHarder board level
Write the output:
public class Test {
static void change(int n) {
n = n * 2;
System.out.println(n);
}
public static void main(String[] args) {
int a = 5;
change(a);
System.out.println(a);
}
}Try it first, then show the solutionSolution
- change(a) copies 5 into n; n becomes 10 and is printed inside the method. (1 mark)
- The caller's a is not affected by the copy, so main prints 5. (1 mark)
Answer: 10
5
Example 3: Pure and impure · 3 marks · Short answerHarder board level
Classify each method as pure or impure and write the output:
class Acct {
int bal = 100;
int show() { return bal + 10; }
void dep(int x) { bal += x; }
}
public class Test {
public static void main(String[] args) {
Acct a = new Acct();
System.out.println(a.show());
a.dep(50);
System.out.println(a.show() + " " + a.bal);
}
}Try it first, then show the solutionSolution
- show() only computes and returns; it does not change bal: pure. dep() changes the data member bal: impure. (1 mark)
- First print: 100 + 10 = 110. (1 mark)
- After dep(50), bal is 150; second line prints 160 and 150. (1 mark)
Answer: show: pure; dep: impure. Output:
110
160 150
Example 4: Case study: modular program · 4 marks · Case-basedHOTS / competency
A program is split into methods:
public class Calc {
static int sq(int n) { return n * n; }
static int sumSq(int a, int b) { return sq(a) + sq(b); }
static void show(String s, int v) {
System.out.println(s + " = " + v);
}
public static void main(String[] args) {
int r = sumSq(3, 4);
show("Total", r);
show("Next", sq(r));
}
}(i) Which methods return a value and which do not? (1)
(ii) Name the actual parameters in the call sumSq(3, 4). (1)
(iii) Write the output. (2)
Try it first, then show the solutionSolution
- (i) sq and sumSq return int values; show is void and returns nothing.
- (ii) The actual parameters are 3 and 4.
- (iii) sumSq(3, 4) = 9 + 16 = 25, so r = 25 and the first line is Total = 25. sq(25) = 625, so the second line is Next = 625.
Answer: (i) sq, sumSq return; show does not (ii) 3 and 4 (iii) Total = 25 and Next = 625
Example 5: Call by reference with an object · 3 marks · Short answerHarder board level
Define call by reference and write the output of:
class Num {
int v;
}
public class Test {
static void inc(Num p) {
p.v += 10;
}
public static void main(String[] args) {
Num n = new Num();
n.v = 5;
inc(n);
System.out.println(n.v);
}
}Try it first, then show the solutionSolution
- Call by reference: the reference (address) of an object is passed, so the formal parameter and the actual parameter refer to the same object. (1 mark)
- inc(n) gives p the same object as n; p.v += 10 changes it from 5 to 15. (1 mark)
- Because the object is shared, main prints 15. (1 mark)
Answer: 15
Where students lose marks in Calling Methods, Parameters, Call by Value and Pure/Impure Methods
The slips examiners see most often, and what to write instead.
Mistake: Saying a primitive argument changes in the caller
Call by value copies the value; the caller's variable is untouched.
Wrong working
After change(a), a = 10
Right working
After change(a), a is still 5
Do this: Print the caller's variable from main separately.
Usually costs: 1 mark
Mistake: Writing the data type in the call
Types appear only in the method header, not in the call.
Wrong working
r = add(int a, int b);
Right working
r = add(a, b);
Do this: Write only the values or variable names in a call.
Usually costs: 1 mark
Mistake: Missing return in a non-void method
A method with a return type must return a value of that type.
Wrong working
int sq(int n) { int r = n * n; }
Right working
int sq(int n) { int r = n * n; return r; }
Do this: Check each path returns.
Usually costs: 1 mark
Exam tips
- Label each method in the answer: header, body, return; examiners give separate marks.
- For call by value, show the copy: n = 5 in the method, a = 5 in main.
- For call by reference, write the definition and one example; no more is asked.
- Say "static, so called without an object" when calling from main.
Practice questions on Calling Methods, Parameters, Call by Value and Pure/Impure Methods
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
A method that does not return any value has the return type:
(a) int (b) null (c) void (d) staticHint
Empty hands.
Answer
(c) void
Q2 · 1 mark · Very short answerBoard level
Where do formal parameters appear: in the method call or in the method header?
Hint
They receive the values.
Answer
In the method header (definition).
Q3 · 2 marks · Short answerHarder board level
Write the output:
static int twice(int x) { x = x * 2; return x; } // in main int n = 4; int m = twice(n); System.out.println(n + " " + m);Hint
Which variable does the method change?
Answer
4 8 (n is unchanged; the returned value 8 is stored in m)
Q4 · 3 marks · Short answerHarder board level
Write a static method isEven(int n) that returns true if n is even and false otherwise. What does System.out.println(isEven(7)); display?
Hint
Use the remainder.
Answer
static boolean isEven(int n) {
return n % 2 == 0;
}
isEven(7): 7 % 2 is 1, so the method returns false and false is displayed.Q5 · 1 mark · Assertion-reasonHOTS / competency
Assertion (A): A method that swaps its two int parameters does not swap the variables used in the call.
Reason (R): Primitive arguments are passed by value, so the method works on copies.
(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
What does the method receive?
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 are actual parameters?Show answer
The values or variables written in the method call.
2.What does a pure method do?Show answer
Returns a value without changing any data member or argument.
3.What is call by value?Show answer
Passing a copy of the value, so the caller's variable is not changed.
4.Can a static method be called without an object?Show answer
Yes, by its name or ClassName.method().
5.What is a method signature?Show answer
The method name with the types of its parameters.
6.What does return do?Show answer
Ends the method and sends a value back to the caller.
Calling Methods, Parameters, Call by Value and Pure/Impure Methods: frequently asked questions
What is the difference between call by value and call by reference?
In call by value a copy of the value is passed and the original is unchanged. In call by reference the address of an object is passed, so the original object can change.
Can a method have no parameters?
Yes. It is written with empty brackets, e.g. void greet().
Is main a user-defined method?
main is a special method that the JVM calls to start the program; the other methods you write are user-defined.