Skip to content
Computer ScienceISC Class 11 · Methods and Constructors

Java Methods, Overloading and Constructors (ISC Class 11 Computer Science)

Updated 17 October 2026 · Fact-checked

A method is a named block of code that performs a task; its header gives the access specifier, return type, name and formal parameters. When a method is called, the actual arguments are passed: primitive values are copied (changes inside do not affect the caller), while objects and arrays are passed by reference value (changes to their contents are visible to the caller). Method overloading uses the same name with different parameter lists. A constructor has the class name, no return type and runs when an object is created.

A primitive is copied, so the original never changes; an array is shared, so changes to its contents show in the caller.

Illustration drawn for QuestionBuddy.

Understand Methods: Arguments, Call by Value, Overloading, and Constructors

Method. Syntax: accessSpecifier returnType name(formal parameters) { body }. A method with void returns nothing; otherwise it uses return value;.

static int sq(int x) { return x * x; }       // x is a formal parameter
int r = sq(5);                                // 5 is the actual argument; r = 25

Actual and formal arguments. Actual arguments are in the call; formal parameters are in the header. They are matched by position, number and type.

Call by value for primitives. The value is copied, so the original is unchanged.

static void change(int x) { x = x + 10; }
int a = 5; change(a);            // a is still 5
static void chg(int[] p) { p[0] = 99; }
int[] q = {1, 2}; chg(q);        // q[0] is now 99 (the array object is shared)

Side effects. A method that changes an object or array argument or a static/instance variable has a side effect.

Method overloading. Several methods with the same name but different number or types of parameters (return type alone is not enough). The compiler picks the closest match. This is static polymorphism.

int add(int a, int b) { return a + b; }
double add(double a, double b) { return a + b; }

add(2, 3) gives 5; add(2.5, 3) gives 5.5; add(2, 3.0) gives 5.0.

Constructors. Same name as the class, no return type (not even void), called automatically by new. *Default constructor:* no parameters, supplied by the compiler if none is written (it sets default values); *parameterised constructor:* receives values; *constructor overloading:* several constructors with different parameters. If any constructor is written, the compiler no longer supplies the default one.

class Box { int l, b;
    Box() { l = 1; b = 1; }
    Box(int x) { l = x; b = x; }
    Box(int x, int y) { l = x; b = y; }
    int area() { return l * b; } }

new Box() has area 1; new Box(4) has area 16; new Box(3, 5) has area 15.

Methods: Arguments, Call by Value, Overloading, and Constructors: key facts

Method header
accessSpecifier returnType name(type param, ...) | void means no return value
Syntax.
Overloading rule
  • Same name
  • Different number or types of parameters
  • Return type alone is not enough
Compile-time choice.
Constructor rules
  • Same name as class
  • No return type
  • Called by new
  • Compiler supplies default only if none is written
Key points.

How to answer Methods: Arguments, Call by Value, Overloading, and Constructors questions

Match actual arguments to formal parameters and track values.

  1. 1Write the formal parameters and the actual arguments side by side.
  2. 2For primitives, copy the value; for arrays and objects, track the shared object.
  3. 3For overloading, pick the method with the exact or nearest parameter types.
  4. 4For constructors, check which one is chosen by the number of arguments.

Methods: Arguments, Call by Value, Overloading, and Constructors 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

Suppose you photocopy your marksheet and hand the copy to a clerk who writes a correction on it.

Does your original change? And what if you gave the original?

Try it first, then show the solutionSolution
  1. The photocopy is like a primitive copy: the original is unchanged.
  2. Handing over the original is like passing an array or object: changes are made to the real thing.

Answer: The original is unchanged for the copy; it changes if the original is handed over.

Memory hook: Primitives are copied; objects are shared.

Tricks to remember Methods: Arguments, Call by Value, Overloading, and Constructors

Short memory aids. Say each one aloud once, then use it on a question the same day.

  • Formal in header, actual in call

    Formal = declared; actual = supplied.

    Use it when: Arguments.

  • Overload = same name, different list

    Not by return type.

    Use it when: Overloading.

  • Constructor has no return type

    Not even void.

    Use it when: Constructors.

Methods: Arguments, Call by Value, Overloading, and Constructors: solved examples

Ordered from board level to HOTS. Try each one before you open the solution.

Example 1: Constructor · 1 mark · MCQBoard level

Which statement about a constructor is correct?
(a) it has a return type void (b) it has the same name as the class (c) it is called by the programmer using the dot operator (d) it cannot take parameters

Try it first, then show the solutionSolution
  1. A constructor has the class name and no return type; new calls it.

Answer: (b) it has the same name as the class

Example 2: Call by value · 3 marks · Short answerBoard level

Give the output:

static void change(int x) { x = x + 10; }
static void chg(int[] p) { p[0] = 99; }
// in main
int a = 5; change(a);
int[] q = {1, 2}; chg(q);
System.out.println(a + " " + q[0] + " " + q[1]);

(3 marks)

Try it first, then show the solutionSolution
  1. change(a) copies 5 into x; a stays 5.
  2. chg(q) passes the array reference; q[0] becomes 99; q[1] stays 2.

Answer: 5 99 2

Example 3: Overloading outputs · 4 marks · Short answerHarder board level

With int add(int a, int b) { return a + b; } and double add(double a, double b) { return a + b; } give the output of: System.out.println(add(2, 3)); System.out.println(add(2.5, 3)); System.out.println(add(2, 3.0)); System.out.println(add(4, 5) / 2); (4 marks)

Try it first, then show the solutionSolution
  1. add(2, 3): both int, the int version: 5.
  2. add(2.5, 3): 3 widens to double: 5.5.
  3. add(2, 3.0): 2 widens: 5.0.
  4. add(4, 5) = 9 (int); 9 / 2 = 4 (integer division).

Answer: 5
5.5
5.0
4

Example 4: Constructor overloading · 5 marks · Long answerHarder board level

For the class Box in the concept, give the output of: Box a = new Box(); Box b = new Box(4); Box c = new Box(3, 5); System.out.println(a.area() + " " + b.area() + " " + c.area()); Then explain what happens if only Box(int x, int y) is defined and a statement Box d = new Box(); is written. (5 marks)

Try it first, then show the solutionSolution
  1. a: l = b = 1, area 1; b: 4 x 4 = 16; c: 3 x 5 = 15.
  2. Output: 1 16 15.
  3. If only a parameterised constructor exists, the compiler does not supply the default one, so new Box() causes a compile-time error (no matching constructor).

Answer: 1 16 15. With only Box(int x, int y) defined, new Box() gives a compile-time error because the default constructor is not supplied.

Example 5: Spot the logic · 5 marks · Long answerHOTS / competency

A programmer writes: static void swap(int x, int y) { int t = x; x = y; y = t; } and calls swap(a, b) with a = 3, b = 7, then prints a and b. Give the output, explain, and show a way to swap the values of an array pair using a method. (5 marks)

Try it first, then show the solutionSolution
  1. x and y are copies of a and b; swapping them does not change a and b.
  2. Output: 3 7.
  3. Pass an array: static void swap(int[] p) { int t = p[0]; p[0] = p[1]; p[1] = t; } with int[] p = {3, 7}; after the call p is {7, 3}.

Answer: Output 3 7 (primitives are copied). Swapping works through an array: after swap(p) the array holds 7 and 3.

Where students lose marks in Methods: Arguments, Call by Value, Overloading, and Constructors

The slips examiners see most often, and what to write instead.

  • Mistake: Giving the constructor a return type

    Writing it like a method.

    Wrong working

    void Box() { }

    Right working

    Box() { }

    Do this: No return type.

    Usually costs: 1-2 marks.

  • Mistake: Assuming primitives change in the caller

    Confusing with arrays.

    Wrong working

    a becomes 15

    Right working

    a stays 5

    Do this: Call by value.

    Usually costs: 2 marks.

  • Mistake: Overloading by return type only

    Misconception.

    Wrong working

    int f(int a) and double f(int a)

    Right working

    Parameters must differ

    Do this: Change the parameter list.

    Usually costs: 1-2 marks.

Exam tips

  • Write formal and actual parameters separately.
  • Say "primitives are passed by value; objects share the same reference".
  • Trace constructors by counting the arguments.

Practice questions on Methods: Arguments, Call by Value, Overloading, and Constructors

Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.

  1. Q1 · 1 mark · MCQBoard level

    Method overloading is also called:
    (a) run-time polymorphism (b) compile-time (static) polymorphism (c) inheritance (d) abstraction

    Hint

    Decided by the compiler.

    Answer

    (b) compile-time (static) polymorphism

  2. Q2 · 3 marks · Short answerBoard level

    Differentiate between a method and a constructor on any three points. (3 marks)

    Hint

    Name, return type, call.

    Answer

    A constructor has the class name, a method has any name; a constructor has no return type, a method has a return type or void; a constructor is called automatically by new, a method is called explicitly.

  3. Q3 · 3 marks · Short answerHarder board level

    Write the output: static int f(int n) { n = n * 2; return n + 1; } int x = 4; int y = f(x); System.out.println(x + " " + y + " " + f(f(2))); (3 marks)

    Hint

    f(2) = 5, f(5) = 11.

    Answer

    x remains 4; f(4) = 9; f(f(2)): f(2) = 5 then f(5) = 11. Output: 4 9 11

  4. Q4 · 5 marks · Long answerHarder board level

    Define a class Student with a default constructor (name "NA", marks 0) and a parameterised constructor, and a method that returns the grade "P" for marks of 40 or more else "F". Give the output for new Student() and new Student("Ravi", 62). (5 marks)

    Hint

    Two objects.

    Answer

    class Student { String name; int marks; Student() { name = "NA"; marks = 0; } Student(String n, int m) { name = n; marks = m; } String grade() { return marks >= 40 ? "P" : "F"; } } new Student().grade() gives F; new Student("Ravi", 62).grade() gives P.

  5. Q5 · 3 marks · Short answerHOTS / competency

    A class has constructors Box(int a) and Box(double a). A call new Box(5) and a call new Box(5.0f) are made. Say which constructor each calls and why, and what happens for new Box(5L). (3 marks)

    Hint

    Widening.

    Answer

    new Box(5) calls Box(int a) (exact match). new Box(5.0f) widens float to double and calls Box(double a). new Box(5L) widens long to double (long cannot go to int), so Box(double a) is called.

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. 1.Constructor name?Show answer

    Same as the class.

  2. 2.Primitive arguments are passed by?Show answer

    Value.

  3. 3.Overloading differs by?Show answer

    Parameter list.

  4. 4.Default constructor supplied when?Show answer

    No constructor is written.

  5. 5.Void means?Show answer

    Returns nothing.

Methods: Arguments, Call by Value, Overloading, and Constructors: frequently asked questions

Can a constructor be overloaded?

Yes.

Can a method return an array?

Yes.

What is a signature?

Name and parameter list.

Can constructors return a value?

No.