User-Defined Methods in Java for ICSE Class 10: Parameters, Return and Overloading
ICSE Class 10 Computer Applications notes on user-defined methods: method prototype and signature, formal and actual parameters, return types, call by value vs call by reference, pure and impure methods, static methods and method overloading, with programs.

User-defined methods (also called functions) let you split a program into small, reusable blocks. In the ICSE Class 10 board exam, they appear in Section A definitions and outputs, and in Section B overloading programs, which come up almost every year.
Parts of a method
public static int sum(int a, int b) { // method header
int s = a + b; // method body
return s; // return statement
}- Access specifier:
public,privateorprotected - Modifier:
static(optional) - Return type:
int, here. Usevoidif the method returns nothing. - Method name:
sum - Parameter list:
(int a, int b)
Method prototype: the first line of the method, public static int sum(int a, int b).
Method signature: the method name together with its parameter list, sum(int a, int b). Java uses the signature to tell overloaded methods apart. The return type is not part of the signature.
Formal and actual parameters
int r = sum(5, 7); // 5 and 7 are ACTUAL parameters (arguments)
int sum(int a, int b) // a and b are FORMAL parameters- Actual parameters are the values passed in the method call.
- Formal parameters are the variables in the method definition that receive those values.
The return statement
- A method can return only one value.
returnends the method immediately, and any statements after it are not executed.- A
voidmethod may use a barereturn;to exit early.
Call by value vs call by reference
Call by value applies to primitive types (int, double, char, boolean). The method receives a copy, so changes inside it do not affect the caller:
static void change(int x) {
x = 100;
}
int n = 5;
change(n);
System.out.println(n); // 5: the original is unchangedCall by reference applies to objects and arrays. The method receives a reference to the same object, so changes to its contents are visible to the caller:
static void change(int arr[]) {
arr[0] = 100;
}
int a[] = {1, 2, 3};
change(a);
System.out.println(a[0]); // 100Pure and impure methods
- A pure method does not change the state of the object (its data members). It usually just computes and returns a value. Example: a method that returns the area of a rectangle.
- An impure method changes the state of the object. Example: a method that updates the balance in a
BankAccount.
Static and non-static methods
- A static method belongs to the class. You call it without an object, using
ClassName.method()or justmethod()from inside the same class. - A non-static (instance) method needs an object:
obj.method().
Method overloading
Overloading means defining several methods with the same name but different parameter lists: a different number, type or order of parameters. Java decides which one to run from the arguments in the call.
A different return type alone is not enough.int f(int x)anddouble f(int x)cannot both exist in one class.
Solved board-style program
Question: Design a class to overload a method series() as follows:
void series(int n): print the first n terms of 1, 4, 9, 16, …double series(double x, int n): return the sum x + x² + x³ + … + xⁿvoid series(): print the Fibonacci series up to 10 terms
class Overload {
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 sum = 0;
for (int i = 1; i <= n; i++)
sum += Math.pow(x, i);
return sum;
}
void series() {
int a = 0, b = 1;
for (int i = 1; i <= 10; i++) {
System.out.print(a + " ");
int c = a + b;
a = b;
b = c;
}
System.out.println();
}
public static void main(String args[]) {
Overload ob = new Overload();
ob.series(5); // 1 4 9 16 25
System.out.println(ob.series(2.0, 3)); // 2 + 4 + 8 = 14.0
ob.series(); // 0 1 1 2 3 5 8 13 21 34
}
}Practice questions
- What is the difference between a method prototype and a method signature?
- Give the output:
static int f(int x) { return x * 2; }called asSystem.out.println(f(f(3))); - Can two methods differ only in their return type? Why or why not?
Answers:
- The prototype is the whole first line, including the return type and access specifier. The signature is just the name and the parameter list.
- f(3) = 6, and f(6) = 12.
- No. The call would be ambiguous, because Java chooses an overloaded method by its parameters, not its return type.
Test yourself with the ICSE Class 10 MCQs on Methods and Constructors, then revise Constructors in Java.
Related Posts
Continue learning with these related articles
Sum of First n Natural Numbers in Java (Loop and Formula)
Find the sum of the first n natural numbers in Java with a for loop, a while loop and the formula n(n + 1)/2, with a dry run and the sums of even numbers, odd numbers, squares and cubes.
Prime Number Program in Java: Check a Number and Print Primes in a Range
Check whether a number is prime in Java by counting its factors, a faster square-root method with isPrime(), and a program that prints all prime numbers in a range.

Encapsulation, Access Specifiers and Scope of Variables in Java for ICSE Class 10
ICSE Class 10 Computer Applications notes on encapsulation: private, default, protected and public access, data hiding with getter and setter methods, instance vs static (class) variables, local variables and scope, with a solved BankAccount program.