Method Overloading and Polymorphism in Java (ICSE Class 10)
Updated 17 October 2026 · Fact-checked
Method overloading means writing several methods in one class with the same name but different parameter lists (different number, types or order of parameters). The compiler selects the version from the arguments in the call. A different return type alone does not make a valid overload. Overloading is the form of polymorphism (one name, many forms) studied in Class X.
Notice that one name, area, has three forms and the compiler picks one from the arguments; a different return type alone is not enough.
Illustration drawn for QuestionBuddy.
Understand Method Overloading and Polymorphism
Definition. Two or more methods in the same class share a name but have different signatures: a different number of parameters, different parameter types, or the same types in a different order. Parameter names and return types do not count.
Valid overloads
int area(int s)andint area(int l, int b): different numberdouble area(double r)andint area(int s): different typevoid g(int a, double b)andvoid g(double a, int b): different order of types
Not valid
int f(int a)anddouble f(int b): same signature, only the return type and the parameter name differ; the compiler reports that the method is already defined.
How the call is matched.
1. The compiler looks for an exact match of number and types.
2. If none exists, it widens the arguments in the order byte → short → int → long → float → double (and char → int) and picks the closest.
3. If it cannot decide, or none fits, it reports an error. With g(int, double) and g(double, int) the call g(3, 4) is ambiguous and does not compile.
Why overload? The same job on different data uses one easy-to-remember name (area, sum). This is compile-time polymorphism: one name, many forms.
Return type. An overloaded method may have different return types, but only if the parameter lists also differ.
Remember. Overloading happens within a class and is decided by the compiler from the arguments; it is not about calling the same method with different values.
Method Overloading and Polymorphism: key facts
- What differs in an overload
- Number of parameters
- Types of parameters
- Order of parameter types
- Not the return type alone
- Not parameter names
- Any one difference is enough.
- Matching a call
- Exact match first
- Then widening: byte, short, int, long, float, double
- char widens to int
- No match or tie: compile-time error
- long goes to float or double, never to int.
- Polymorphism link
- Method overloading = compile-time polymorphism | One name, many forms
- The syllabus treats it as polymorphism in Class X.
- Invalid overload
- Same name
- Same parameter types in the same order
- Different return type only
- Compiler error: method already defined.
How to answer Method Overloading and Polymorphism questions
Use this routine for questions on which overloaded method runs.
- 1List every version with its parameter types.
- 2Write the type of each argument in the call.
- 3Pick the version whose parameter types match exactly.
- 4If none matches exactly, widen each argument (int to long, float, double) and choose the nearest.
- 5If two versions fit equally, say the call is ambiguous (a compile-time error).
Method Overloading and Polymorphism 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.
One word, different jobs
Suppose a school app has a single "Print" button that prints a single page, a range of pages or a whole file, depending on what the user selects.
Which OOP idea does this match and how is it coded in Java?
Try it first, then show the solutionSolution
- One name with different forms is polymorphism.
- In Java: methods print(int page), print(int from, int to) and print(String file) in one class.
Answer: Polymorphism by method overloading.
Memory hook: Same name, different inputs.
Tricks to remember Method Overloading and Polymorphism
Short memory aids. Say each one aloud once, then use it on a question the same day.
N-T-O
Overloads differ in Number, Type or Order of the parameters, never only in return type.
Use it when: Validity checks.
Smaller to bigger
Arguments climb up to the next bigger type if there is no exact match, never down.
Use it when: Which method is called.
Compiler chooses
Overloading is decided by the compiler from the arguments in the call.
Use it when: Explaining polymorphism.
Method Overloading and Polymorphism: solved examples
Ordered from board level to HOTS. Try each one before you open the solution.
Example 1: Definition · 3 marks · Short answerBoard level
What is method overloading? State two ways in which overloaded methods can differ and give an example of such methods.
Try it first, then show the solutionSolution
- Method overloading is having several methods with the same name in a class, with different parameter lists. (1 mark)
- They can differ in the number of parameters or in the types (or order of types) of parameters. (1 mark)
- Example: int sum(int a, int b) and int sum(int a, int b, int c). (1 mark)
Answer: Same name, different parameter lists (number, type or order); e.g. sum(int, int) and sum(int, int, int).
Example 2: Which version runs · 3 marks · Short answerHarder board level
Write the output:
public class Test {
static int area(int s) { return s * s; }
static int area(int l, int b) { return l * b; }
static double area(double r) { return 3.14 * r * r; }
public static void main(String[] args) {
System.out.println(area(5) + " " + area(4, 3) + " " + area(2.0));
}
}Try it first, then show the solutionSolution
- area(5): one int argument matches area(int): 25. (1 mark)
- area(4, 3): two int arguments match area(int, int): 12. (1 mark)
- area(2.0): a double matches area(double): 3.14 * 2.0 * 2.0 = 12.56. (1 mark)
Answer: 25 12 12.56
Example 3: Widening in overload resolution · 4 marks · Short answerHarder board level
Write the output:
public class Test {
static void show(int x) { System.out.println("int"); }
static void show(double x) { System.out.println("double"); }
public static void main(String[] args) {
show(7);
show('a');
show(5L);
show(3.5f);
}
}Try it first, then show the solutionSolution
- show(7): exact match with show(int): int. (1 mark)
- show('a'): no char version, so char widens to int: int. (1 mark)
- show(5L): long cannot go down to int, so it widens to double: double. (1 mark)
- show(3.5f): float widens to double: double. (1 mark)
Answer: int
int
double
double
Example 4: Case study: valid or not · 4 marks · Case-basedHOTS / competency
A class contains the following pairs. For each pair state whether it is a valid overload or gives an error, with a reason:
(i) int f(int a) and double f(int b)
(ii) void g(int a, double b) and void g(double a, int b)
(iii) void h(int a) and void h(int a, int b)
(iv) For the pair in (ii), what happens with the call g(3, 4)?
Try it first, then show the solutionSolution
- (i) Error: the parameter types are the same (int); only the return type and parameter name differ, so the signature is a repeat.
- (ii) Valid: the order of the types differs.
- (iii) Valid: the number of parameters differs.
- (iv) Both versions need one widening (int to double), so the call is ambiguous and gives a compile-time error.
Answer: (i) error (ii) valid (iii) valid (iv) ambiguous call, compile-time error
Example 5: Writing overloaded methods · 4 marks · Short answerHarder board level
Write three overloaded methods named sum: for two ints, three ints and two doubles, all returning the sum. Show the output of System.out.println(sum(2, 3) + " " + sum(2, 3, 4) + " " + sum(1.5, 2.5));
Try it first, then show the solutionSolution
- static int sum(int a, int b) { return a + b; } (1 mark)
- static int sum(int a, int b, int c) { return a + b + c; } (1 mark)
- static double sum(double a, double b) { return a + b; } (1 mark)
- sum(2, 3) = 5, sum(2, 3, 4) = 9, sum(1.5, 2.5) = 4.0, so the line is 5 9 4.0. (1 mark)
Answer: 5 9 4.0
Where students lose marks in Method Overloading and Polymorphism
The slips examiners see most often, and what to write instead.
Mistake: Treating a different return type as an overload
The compiler cannot tell the versions apart from a call.
Wrong working
int f(int a) and double f(int a) are overloaded
Right working
They have the same signature: compile-time error
Do this: Change the parameter list.
Usually costs: 1 mark
Mistake: Matching long to the int version
Widening goes upward only: long cannot be passed to an int parameter without a cast.
Wrong working
show(5L) prints int
Right working
show(5L) prints double (long widens to double)
Do this: Follow byte, short, int, long, float, double.
Usually costs: 1 mark
Mistake: Writing overloaded method names with different spellings
Overloading needs the exact same name.
Wrong working
sum() and sums()
Right working
sum() and sum(int a)
Do this: Keep the name identical.
Usually costs: 1 mark
Exam tips
- In definition answers, say "same name, different parameter lists" and give both an example and the principle (polymorphism).
- In trace questions, write the argument types before choosing the version.
- Know that char widens to int and long widens to float/double.
- Mention that overloading is resolved by the compiler.
Practice questions on Method Overloading and Polymorphism
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
Which pair of methods is a valid example of overloading?
(a) int f(int a) and void f(int a) (b) void f(int a) and void f(double a) (c) void f(int a) and void f(int b) (d) int f(int a) and int f(int a)Hint
Look at the parameter types only.
Answer
(b) void f(int a) and void f(double a)
Q2 · 1 mark · Very short answerBoard level
Which OOP principle is shown by method overloading?
Hint
One name, many forms.
Answer
Polymorphism.
Q3 · 2 marks · Short answerHarder board level
Write the output:
static void p(int a) { System.out.print("A"); } static void p(int a, int b) { System.out.print("B"); } static void p(double a) { System.out.print("C"); } // in main p(1); p(1, 2); p(1.5); p('x');Hint
char widens to int before double.
Answer
ABCA
Q4 · 3 marks · Short answerHarder board level
Write two overloaded methods named big: one that returns the larger of two ints and one that returns the larger of two doubles. State the values printed for big(3, 9) and big(2.5, 1.5).
Hint
Use if or the ternary operator.
Answer
static int big(int a, int b) { return a > b ? a : b; }
static double big(double a, double b) { return a > b ? a : b; }
big(3, 9) gives 9 and big(2.5, 1.5) gives 2.5.Q5 · 1 mark · Assertion-reasonHOTS / competency
Assertion (A): Changing only the return type of a method does not overload it.
Reason (R): The compiler chooses an overloaded method using the name and the parameter list of the call.
(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
Does the call mention the return type?
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 must differ in overloaded methods?Show answer
The parameter list: number, types or order of types.
2.Is overloading allowed with only a different return type?Show answer
No.
3.Which type does char widen to?Show answer
int
4.Which OOP principle does overloading illustrate?Show answer
Polymorphism.
5.What is an ambiguous call?Show answer
A call where two versions fit equally well; it gives a compile-time error.
6.Who decides which overloaded version runs?Show answer
The compiler, from the arguments.
Method Overloading and Polymorphism: frequently asked questions
Can constructors be overloaded?
Yes. Constructors with different parameter lists in one class are overloaded constructors (see the Constructors chapter).
Is calling the same method with different values overloading?
No. Overloading needs different method definitions with the same name.
Do parameter names matter in overloading?
No. Only the types, number and order of the parameters matter.