User-defined Methods ICSE Class 10 Computer Applications
Updated 14 October 2026 · Fact-checked
A user-defined method is a named block of code written by the programmer to do one task, called whenever needed. It has a header (access specifier, return type, name, parameters) and a body. ICSE Class 10 tests calling methods, actual and formal parameters, call by value and reference, pure and impure methods, and overloading.
What User-defined Methods is about
Methods let you break a big program into small, reusable parts (modular programming). Method overloading appears in Section B every year in this period: perform() in 2024 (cone area, a number pattern, and quotient and remainder) and print() in 2025 (a pattern, a series, and ASCII difference). Examiners deducted marks for changing the given method names or signatures, accepting values inside methods instead of using the arguments, and printing a value when the method should return it. Section A asked about pure methods (2024), call by reference (2024) and invalid overloading (2025).
The syllabus asks for the need for methods, syntax and forms, definition and calling, actual and formal parameters, static and non-static methods, the prototype or signature, pure and impure methods, call by value (with programs) and call by reference (definition with an example), returning values, and overloading.
Weightage: CISCE publishes no chapter weightage. Section A (40 marks) is compulsory: 1-mark MCQs and 2-mark short answers including output and error questions; in Section B you answer any four of six 15-mark programming questions written in Java.Source: CISCE ICSE Computer Applications (661) specimen paper structure for 2027
Key concepts
- Need, syntax, prototype and signature
Need for methods: (1) reuse code instead of repeating it; (2) break a large problem into small modules (modular programming); (3) make programs easier to read, test and correct; (4) hide details (abstraction).
Syntax:
accessSpecifier modifier returnType methodName(parameter list)
{
body
return value; // if returnType is not void
}
Example:
public static int square(int n)
{
return n * n;
}Method prototype (header): the first line: public static int square(int n).
Method signature: the method name together with the number, types and order of its parameters: square(int). The return type is not part of the signature.The return statement sends a value back to the caller and ends the method; a void method returns no value.
Worked example
(2 marks) For the method double interest(double p, double r, int t), write the prototype and the signature.
Try it first, then show the solutionSolution
- Prototype: double interest(double p, double r, int t) - 1 mark.
- Signature: interest(double, double, int): name and parameter types only - 1 mark.
Answer: Prototype: double interest(double p, double r, int t). Signature: interest(double, double, int).
- Calling methods; actual and formal parameters; static and non-static
A method runs only when it is called (invoked). A non-static (instance) method is called through an object: ob.display(); a static method can be called with the class name or directly from another static method in the same class: Calc.square(4) or square(4).
Formal parameters: the variables in the method header that receive values: int n in square(int n).
Actual parameters (arguments): the values or variables passed in the call: 4 in square(4), or x in square(x).
Actual and formal parameters must match in number, type and order.If a method returns a value, the call can be used in an expression: int y = square(5) + 1; gives 26.
Worked example
(2 marks) In int sum = add(a, 7); and int add(int x, int y) { return x + y; }, identify the actual and formal parameters.
Try it first, then show the solutionSolution
- Actual parameters (in the call): a and 7 - 1 mark.
- Formal parameters (in the header): x and y - 1 mark.
Answer: Actual parameters: a and 7. Formal parameters: x and y.
- Call by value and call by reference
Call (pass) by value: a copy of the actual parameter's value is given to the formal parameter. Changes made to the formal parameter inside the method do not affect the original variable. Primitive types (int, double, char, boolean) are always passed by value.
class Demo
{
void change(int x)
{
x = x * 2;
System.out.println("Inside: " + x);
}
public static void main(String args[])
{
Demo d = new Demo();
int a = 5;
d.change(a);
System.out.println("Outside: " + a);
}
}
Output:
Inside: 10
Outside: 5Call (pass) by reference: the method receives a reference (address) to the actual object, so changes made through it affect the original. In Java this happens when objects or arrays are passed. Example: a method void doubleAll(int arr[]) that runs arr[i] = arr[i] * 2; for every element changes the caller's array {1, 2, 3} to {2, 4, 6}.
Worked example
(1 mark) Invoking a method by passing objects of a class is termed:
(a) call by reference
(b) call by value
(c) call by method
(d) call by constructorTry it first, then show the solutionSolution
- Passing an object passes a reference to it.
Answer: (a) call by reference
- Pure and impure methods
Pure method (accessor): does not change the state of the object (its member variables) or anything outside it; it usually computes and returns a value from its parameters, and gives the same result for the same arguments. Example: int reverse(int n) that returns the reverse of n; boolean isPrime(int n).
Impure method (mutator / modifier): changes the state of the object, such as modifying member variables (or an array passed to it). Example: void deposit(double amt) { balance = balance + amt; }
Pure methods are easier to test because their output depends only on their input.
Worked example
(1 mark) A method that reverses a given number and returns it, without changing any member variable, is:
(a) impure
(b) pure
(c) a constructor
(d) a destructorTry it first, then show the solutionSolution
- It only computes and returns; no state change.
Answer: (b) pure
- Method overloading (polymorphism)
Method overloading means defining several methods in the same class with the same name but different parameter lists (different number, types or order of parameters). Java chooses which one to run by matching the arguments in the call. It is compile-time polymorphism.
Valid overloads:
void test(int a, int b) and void test(double a, double b) (types differ)
void test(int a, double b) and void test(double a, int b) (order differs)
void test(int a, double b) and void test(int a) (number differs)Invalid: void test(int a) and int test(int a): only the return type differs; the signatures are identical, so it is a compile-time error.
In board questions, use exactly the signatures given, take values from the parameters (do not accept them again with Scanner inside), and return a value when the return type is not void.
Worked example
(1 mark) Which pair causes a compile-time error?
(a) void test(int a, int b) and void test(double a, double b)
(b) void test(int a, double b) and void test(double a, int b)
(c) void test(int a, double b) and void test(int a)
(d) void test(int a) and int test(int a)Try it first, then show the solutionSolution
- (d) has the same name and the same parameter list; return type alone cannot distinguish them.
Answer: (d) void test(int a) and int test(int a)
User-defined Methods in real life
Each concept, met in an everyday situation. Read the situation, answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.
Method overloading
Suppose a food app has one 'order' button that works whether you send just an item, an item with quantity, or an item, quantity and delivery time.
How does this resemble method overloading?
Try it first, then show the solutionSolution
- One name (order) handles different sets of inputs.
- The app chooses what to do from what you give it.
- In Java: order(String), order(String, int), order(String, int, String).
Answer: It is like overloading: one method name with different parameter lists, and the right version is chosen from the arguments supplied.
Memory hook: Same name, different inputs.
Call by value
Imagine you photocopy your notes and give the copy to a friend, who scribbles on it. Your original notes stay clean.
Which parameter-passing method does this model?
Try it first, then show the solutionSolution
- The friend receives a copy, not the original.
- Changes to the copy do not affect the original.
- That is call by value.
Answer: Call by value: the method works on a copy, so the caller's variable is unchanged.
Memory hook: Value = photocopy; reference = the original notebook.
Pure vs impure
Suppose a calculator's 'square root' button just shows a result, while its 'M+' button adds the number to the stored memory.
Which button is like a pure method and which like an impure one?
Try it first, then show the solutionSolution
- Square root computes and returns without changing stored state: pure.
- M+ changes the stored memory value: impure.
Answer: Square root is like a pure method; M+ is like an impure method because it changes stored state.
Memory hook: Pure looks; impure touches.
Topics in this chapter
User-defined Methods: syntax and key facts
- Method header
- accessSpecifier [static] returnType name(type p1, type p2, …)
- void if nothing is returned.
- Signature
- name + number, types and order of parameters (not return type)
- Overloads must differ in signature.
- Parameter passing
- 1.Primitives
- 2.by value (copy); objects/arrays
- 3.by reference
- Programs only for call by value in the syllabus.
- Calling
- object.method(args) for non-static; ClassName.method(args) or method(args) for static
How the board asks User-defined Methods
The question patterns to expect, and the method that works for each.
| Question type | How it is asked | Method |
|---|---|---|
| MCQ (Section A) | Pure method for reversing a number (2024); call by reference when passing objects (2024); invalid overloading pair (2025). | Signature = name + parameters; pure = no state change; objects pass by reference. |
| Short answer / error (2 marks) | Actual vs formal parameters; find the error in a method; output of call by value. | Trace the copy separately from the original variable. |
| Program (15 marks) | Overload a method with three given signatures (perform() 2024, print() 2025). | Copy each signature exactly; use the parameters; return when the type is not void; main is not needed unless asked. |
Tricks to remember User-defined Methods
Short memory aids. Say each one aloud once, then use it on a question the same day.
NTO decides overloading
Number, Type, Order of parameters can differ; the return type alone cannot.
Use it when: Valid vs invalid overloads.
AF: Actual in the cAll, Formal in the header
Actual values travel in the call; formal names wait in the definition.
Use it when: Parameter questions.
User-defined Methods: board-level solved questions
Ordered from board level to HOTS. Cover the solution, write your own, then compare step by step.
Example 1: Signature · 1 mark · MCQBoard level
Which is the signature of int max(int a, int b)?
(a) int max
(b) max(int, int)
(c) int max(int, int)
(d) max
Try it first, then show the solutionSolution
- Signature: name and parameter types; return type excluded.
Answer: (b) max(int, int)
Example 2: Assertion and reason: pass by value · 1 mark · Assertion-reasonHarder board level
Assertion (A): When an int variable is passed to a method and changed inside it, the original variable is not changed.
Reason (R): Primitive values are passed by value, so the method gets a copy.
(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
Try it first, then show the solutionSolution
- A copy is changed; the original stays the same.
Answer: (a) Both A and R are true and R is the correct explanation of A
Example 3: Trace a returning method · 2 marks · Short answerHarder board level
Give the output:
class T
{
static int f(int n)
{
int s = 0;
while (n > 0)
{
s = s + n % 10;
n = n / 10;
}
return s;
}
public static void main(String args[])
{
int n = 482;
int r = f(n);
System.out.println(n + " " + r + " " + f(r));
}
}
Try it first, then show the solutionSolution
- f(482) = 4 + 8 + 2 = 14; n in main stays 482 (passed by value).
- f(14) = 5; output joins them.
Answer: 482 14 5
Example 4: Fix the method · 2 marks · Short answerHOTS / competency
The method should return the cube of n. Find two errors and correct them:
void cube(int n)
{
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
System.out.println(n * n * n);
}
Try it first, then show the solutionSolution
- It accepts n again instead of using the argument passed.
- It prints instead of returning; the return type should be int.
Answer: int cube(int n)
{
return n * n * n;
}
Example 5: Call by value output · 2 marks · Very short answerHarder board level
Give the output:
class V
{
void swap(int x, int y)
{
int t = x; x = y; y = t;
System.out.println(x + " " + y);
}
public static void main(String args[])
{
int a = 3, b = 9;
V v = new V();
v.swap(a, b);
System.out.println(a + " " + b);
}
}
Try it first, then show the solutionSolution
- Inside swap the copies are exchanged: 9 3.
- a and b in main are unchanged: 3 9.
Answer: 9 3
3 9
Example 6: Overloaded calc() (Section B) · 15 marks · Long answerHarder board level
Define a class Overload with: (i) double calc(double r) - return the area of a circle, 22/7 × r²; (ii) int calc(int a, int b) - return the sum of all integers from a to b; (iii) void calc(String w) - print the number of vowels in w. Write main() to call calc(7.0), calc(3, 6) and calc("Education").
Try it first, then show the solutionSolution
- class Overload
{
double calc(double r)
{
return 22.0 * r * r / 7;
} - int calc(int a, int b)
{
int s = 0;
for (int i = a; i <= b; i++)
s = s + i;
return s;
} - void calc(String w)
{
int c = 0;
for (int i = 0; i < w.length(); i++)
{
char ch = w.charAt(i);
if ("AEIOUaeiou".indexOf(ch) != -1)
c++;
}
System.out.println("Vowels = " + c);
} - public static void main(String args[])
{
Overload ob = new Overload();
System.out.println(ob.calc(7.0));
System.out.println(ob.calc(3, 6));
ob.calc("Education");
}
} - Trace: 22.0 × 49 / 7 = 1078.0 / 7 = 154.0; 3 + 4 + 5 + 6 = 18; Education: E, u, a, i, o = 5.
Answer: Output:
154.0
18
Vowels = 5
Example 7: Prime method · 15 marks · Long answerHOTS / competency
Write a pure method boolean isPrime(int n) and use it in main() to print all prime numbers from 10 to 30.
Try it first, then show the solutionSolution
- class Primes
{
static boolean isPrime(int n)
{
if (n < 2) return false;
for (int i = 2; i <= n / 2; i++)
if (n % i == 0) return false;
return true;
} - public static void main(String args[])
{
for (int k = 10; k <= 30; k++)
if (isPrime(k))
System.out.print(k + " ");
}
} - return false ends the method as soon as a factor is found.
- isPrime is pure: it uses only its parameter and returns a value.
- Trace: primes between 10 and 30 are 11, 13, 17, 19, 23, 29.
Answer: Output: 11 13 17 19 23 29
Case-study practice (Section B style)
Read the situation, then answer every part. In the board paper this is a 10-mark question split into 2 + 3 + 5 marks.
Reviewing an overloading answer
Imagine the question asks for: double perform(double r, double h) - return the curved surface area of a cone, πrl where l = √(r² + h²); void perform(int r, int c) - print r rows of 1 to c; void perform(int m, int n, char ch) - print the quotient if ch is 'Q' or the remainder otherwise. A student names the methods perform1, perform2 and perform3, reads r and h with Scanner inside the first, and prints the area instead of returning it.
(i) · 2 marks
Why will the examiner deduct marks for perform1, perform2 and perform3?
Answer
Answer: The question requires method overloading: all three must be named perform with the given parameter lists. Different names are not overloading.
1 mark each point.
(ii) · 3 marks
Write the first method correctly.
Answer
Answer: double perform(double r, double h)
{
double l = Math.sqrt(r * r + h * h);
return Math.PI * r * l;
}l 1 mark; formula 1 mark; return 1 mark.
(iii) · 5 marks
Write the third method and give its output for perform(17, 5, 'Q') and perform(17, 5, 'R').
Answer
Answer: void perform(int m, int n, char ch)
{
if (ch == 'Q')
System.out.println("Quotient = " + (m / n));
else
System.out.println("Remainder = " + (m % n));
}
Outputs: Quotient = 3; Remainder = 2.Method 3 marks; outputs 1 mark each.
Where the marks are
How a typical answer is split into step marks. Show every step: a right final answer alone rarely earns full marks.
Identify actual and formal parameters. (2 marks) (2 marks)
| Step | Marks |
|---|---|
| Actual parameters from the call. | 1 |
| Formal parameters from the header. | 1 |
Overload a method with three given signatures. (15 marks) (15 marks)
| Step | Marks |
|---|---|
| Class and three methods with exactly the given name and signatures. | 3 |
| Method 1: correct logic and return. | 4 |
| Method 2: correct loop/logic using parameters. | 4 |
| Method 3: correct logic and output. | 3 |
| No re-input of parameters; main/object if asked. | 1 |
Where students lose marks in User-defined Methods
The slips examiners see most often, and what to write instead.
Mistake: Not applying overloading or changing method names
The 2024 and 2025 examiners reported separate programs or renamed methods.
Do this: Use exactly the method name and signatures given.
Usually costs: 3 marks or more.
Mistake: Accepting values inside methods
The 2024 examiners reported values accepted inside the perform() methods instead of using the arguments.
Do this: Parameters already carry the values; use them directly.
Usually costs: 1 to 2 marks per method.
Mistake: Printing instead of returning
In 2024 (cone area) and 2025 (series sum) candidates printed values from methods declared to return them.
Do this: If the return type is not void, end with return value;.
Usually costs: 1 to 2 marks.
Mistake: Thinking return type alone overloads a method
The 2025 MCQ tested this.
Do this: Signatures must differ in number, type or order of parameters.
Usually costs: 1 mark.
Practice questions on User-defined 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
The keyword used when a method returns no value is:
(a) null
(b) void
(c) static
(d) returnHint
Empty return type.
Answer
(b) void
Q2 · 1 mark · MCQBoard level
Parameters in the method definition are called:
(a) actual parameters
(b) formal parameters
(c) arguments
(d) constantsHint
Header.
Answer
(b) formal parameters
Q3 · 2 marks · Very short answerBoard level
Distinguish between pure and impure methods.
Hint
State change.
Answer
A pure method does not change the state of the object; it returns a value computed from its parameters (e.g. reverse(int n)). An impure method changes the object's state, such as its member variables (e.g. deposit(double amt) changing balance).
Q4 · 2 marks · Very short answerHarder board level
Distinguish between call by value and call by reference.
Hint
Copy vs address.
Answer
In call by value a copy of the value is passed, so changes inside the method do not affect the original (primitive types). In call by reference a reference to the object is passed, so changes made through it affect the original (objects and arrays).
Q5 · 2 marks · Short answerHarder board level
Give the output:
static int g(int a)
{
a = a + 5;
return a * 2;
}
...
int x = 3;
int y = g(x);
System.out.println(x + "," + y);Hint
x is copied.
Answer
3,16
Q6 · 2 marks · Short answerHOTS / competency
Why is overloading called polymorphism?
Hint
Many forms.
Answer
Because one method name takes many forms: the same name performs different tasks depending on the arguments, which is the meaning of polymorphism (many forms).
Q7 · 15 marks · Long answerHarder board level
Define a class to overload the method series: void series(int n) prints the first n square numbers (1 4 9 ...); double series(double x, int n) returns x + x² + ... + xⁿ. Write main() to call series(5) and print series(2.0, 4).
Hint
Math.pow for powers.
Answer
class Series
{
void series(int n)
{
for (int i = 1; i <= n; i++)
System.out.print(i * i + " ");
System.out.println();
}
double series(double x, int n)
{
double s = 0;
for (int i = 1; i <= n; i++)
s = s + Math.pow(x, i);
return s;
}
public static void main(String args[])
{
Series ob = new Series();
ob.series(5);
System.out.println(ob.series(2.0, 4));
}
}
Output:
1 4 9 16 25
30.0 (2 + 4 + 8 + 16)Q8 · 2 marks · Very short answerBoard level
Write a method int countDigits(long n) that returns the number of digits, and state whether it is pure.
Hint
Divide by 10.
Answer
int countDigits(long n)
{
int c = 0;
do
{
c++;
n = n / 10;
} while (n > 0);
return c;
}
It is pure: it changes only its own copy of n and returns a value. (do-while makes 0 count as 1 digit.)Q9 · 2 marks · Short answerHOTS / competency
Suppose a class has void show(int a, double b) and void show(double a, int b). Which runs for show(4, 5)? Explain.
Hint
Ambiguity.
Answer
Neither can be chosen: both need one int widened to double, so the call is ambiguous and the compiler reports an error. A call such as show(4, 5.0) would choose show(int, double).
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.Is the return type part of the signature?Show answer
No.
2.How are primitives passed in Java?Show answer
By value.
3.A method that changes member variables is?Show answer
Impure.
4.Same name, different parameter lists is called?Show answer
Method overloading.
5.Which statement sends a value back?Show answer
return
Best order to study it
- Need for methods; header, prototype, signature.
- Calling methods; static vs non-static.
- Actual and formal parameters.
- Call by value (programs) and call by reference (definition, example).
- Pure and impure methods; returning values.
- Method overloading programs.
Quick revision checklist
The night before the exam: can you do each of these without looking?
- Method = named block for one task; reuse and modularity.
- Prototype = header; signature = name + parameter types.
- Actual in call, formal in header; match number, type, order.
- Primitives by value; objects/arrays by reference.
- Pure: no state change; impure: changes state.
- Overloading: same name, different parameters; return type alone is not enough.
User-defined Methods: frequently asked questions
Do I need main() in an overloading question?
Only if the question asks for it. The 2024 examiners noted that an object need not be created when only the methods are asked for.
Can a void method use return?
Yes, return; (with no value) ends a void method early.
Can I write programs on call by reference?
The syllabus asks only for its definition with an example; programs are required for call by value.
Based on: CISCE ICSE 2027 Computer Applications syllabus; CISCE Analysis of Pupil Performance ICSE 2025: Computer Applications (with the 2025 board paper)