Skip to content
Computer ScienceISC Class 12 · Methods

Methods, Arguments, Static Members and Overloading (ISC Class 12 Computer Science)

Updated 17 October 2026 · Draft, not yet fact-checked

Actual arguments in a call are copied into the formal parameters of the method. A primitive argument is copied by value, so the method cannot change the caller's variable; an object or array argument copies the reference, so changes to the object are visible but reassigning the parameter is not. static members belong to the class and are shared by all objects.

Top boxes are the caller, bottom boxes the method: a copied value cannot change x, but a copied reference reaches the same object.

Illustration drawn for QuestionBuddy.

Understand Methods, Arguments, Static Members and Method Overloading

Method structure. returnType name(formal parameters) { body }. A method is an abstraction of an operation on an object: callers need only its name, arguments and result. A void method returns nothing; other methods use return value;.

Formal and actual arguments. The parameters in the method definition are the formal arguments; the values supplied in the call are the actual arguments. Calling copies each actual into the corresponding formal, matched by position and type.

Primitive versus object arguments. Java passes a copy of the argument. For a primitive the copy is the value, so changes inside the method do not affect the caller: a swap(int a, int b) method does not swap the caller's variables. For an object or array the copy is the reference: the method can change the contents of the same object (p.x += 5 or arr[0] = 9 are seen by the caller), but assigning a new object to the parameter (p = new Pt(0)) changes only the local copy.

Static variables and methods. A static variable is one shared copy for the whole class, accessed as ClassName.var; an instance variable has a separate copy in every object. A static method belongs to the class, can be called as ClassName.method() without an object, and can use only static members directly (it has no this). main is static for this reason.

The this operator. Inside an instance method or constructor this refers to the object on which the method was called; it separates a field from a same-named parameter and can pass the current object to another method.

Method overloading. Several methods may share a name if their parameter lists differ in number or types of parameters; the compiler picks the version from the actual arguments (compile-time polymorphism). The return type alone cannot distinguish overloaded methods.

Algorithmic problem solving with methods. Number problems (prime test, HCF, digit sum, perfect number) are written as small methods that take int arguments and return a result, and are called from main or from another method.

Constructors are in the Objects chapter; recursion, where a method calls itself, has its own chapter.

Methods, Arguments, Static Members and Method Overloading: key facts

Argument passing
  • Primitive: the value is copied, caller unchanged
  • Object or array: the reference is copied, contents can change
  • Reassigning the parameter never changes the caller
Java passes everything by value.
static versus instance
static variableone copy for the class
Instance variableone copy per object
static methodno this, call by ClassName.method()
A static method cannot use instance variables directly.
Overloading rules
  • Same name
  • Different number or types of parameters
  • Return type alone is not enough
  • Chosen at compile time
area(int), area(int, int), area(double) are valid overloads.
Method header
  • returnType name(type param, ...)
  • void returns nothing
  • return ends the method
  • Formal parameters get copies of the actual arguments
Match the number, order and type of arguments.

How to answer Methods, Arguments, Static Members and Method Overloading questions

Use this routine for argument-passing and static questions.

  1. 1Mark which arguments are primitives and which are objects or arrays.
  2. 2For each call, copy the actual values into the formal parameters.
  3. 3Execute the body: changes to a primitive parameter stay local; changes through a reference reach the shared object.
  4. 4Track static variables in one shared cell and instance variables per object.
  5. 5For overloaded calls, match the number and types of actual arguments to the signature.
  6. 6Print the caller's variables after the call to see what really changed.

Methods, Arguments, Static Members and Method Overloading 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.

Photocopy versus original

Suppose a program passes a student's mark (an int) to a method that adds 10 bonus marks, and also passes an array of marks to a similar method.

With the mark 5 and the array {5}, what does the caller hold after both methods add 10?

Try it first, then show the solutionSolution
  1. The int is copied, so the caller's mark stays 5.
  2. The array reference is copied, so the array element becomes 15.

Answer: The int stays 5; the array element is 15.

Memory hook: A copy of a number is a photocopy; a copy of a reference is a second key to the same room.

Counting tickets sold across counters

Suppose each Counter object creates a ticket and a static variable total counts all tickets from all counters.

After three Counter objects are created, what is total, and what is the id of the last one if id is the value of total at creation?

Try it first, then show the solutionSolution
  1. Each constructor adds 1 to the shared total: 3 in the end.
  2. The last object copied total = 3 into its id.

Answer: total = 3 and the last id is 3.

Memory hook: static is the shared notice board.

Tricks to remember Methods, Arguments, Static Members and Method Overloading

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

  • Formal is form, actual is act

    Formal parameters sit in the method definition (form); actual arguments are what the caller actually sends.

    Use it when: Terminology marks.

  • Copy of a reference

    The method gets a copy of the key, not a new room: it can change the room but not give you a new key.

    Use it when: Object argument questions.

  • static = class-wide

    One copy for the class, called with the class name.

    Use it when: Static variable and method questions.

  • Overload by arguments

    Same name, different arguments; the return type does not count.

    Use it when: Method overloading questions.

Methods, Arguments, Static Members and Method Overloading: solved examples

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

Example 1: Static variable · 1 mark · MCQBoard level

A static variable of a class
(a) has a separate copy in every object (b) is shared by all objects of the class (c) cannot be changed (d) can be used only inside constructors

Try it first, then show the solutionSolution
  1. A static variable is created once for the class and shared.

Answer: (b) is shared by all objects of the class

Example 2: Primitive versus array argument · 3 marks · Short answerHarder board level

Write the output:

static void change(int a, int[] arr) {
    a = a + 10;
    arr[0] = arr[0] + 10;
}
// in main
int x = 5;
int[] y = {5};
change(x, y);
System.out.println(x + " " + y[0]);
Try it first, then show the solutionSolution
  1. a receives a copy of 5; a becomes 15 inside the method but x stays 5. (1.5 marks)
  2. arr holds the same array as y, so y[0] becomes 15. (1 mark)
  3. Output: 5 15. (0.5 mark)

Answer: 5 15

Example 3: Static counter and instance id · 3 marks · Short answerHarder board level

Write the output:

class Counter {
    static int total = 0;
    int id;
    Counter() { total++; id = total; }
}
// in main
Counter a = new Counter();
Counter b = new Counter();
Counter c = new Counter();
System.out.println(a.id + " " + c.id + " " + Counter.total);
Try it first, then show the solutionSolution
  1. Each constructor increases the shared total and copies it to id: a.id = 1, b.id = 2, c.id = 3. (2 marks)
  2. total is 3 at the end. Output: 1 3 3. (1 mark)

Answer: 1 3 3

Example 4: Number problem with a method · 4 marks · Short answerHarder board level

Write a method boolean isPrime(int n) and use it to print the count and the sum of primes from 1 to 20.

Try it first, then show the solutionSolution
  1. static boolean isPrime(int n) {
        if (n < 2) return false;
        for (int i = 2; i * i <= n; i++)
            if (n % i == 0) return false;
        return true;
    }
    // in main
    int c = 0, s = 0;
    for (int k = 1; k <= 20; k++)
        if (isPrime(k)) { c++; s += k; }
    System.out.println(c + " " + s);
    (2.5 marks for the method and the caller)
  2. Primes up to 20 are 2, 3, 5, 7, 11, 13, 17, 19: eight primes. Their sum is 77. (1 mark)
  3. Output: 8 77. (0.5 mark)

Answer: 8 77

Example 5: Case: points and swaps · 4 marks · Case-basedHOTS / competency

Suppose a drawing program has a class Pt with a field x and a constructor Pt(int x) { this.x = x; }, and these static methods:

static void move(Pt p)   { p.x += 5; }
static void reset(Pt p)  { p = new Pt(0); }
static void swap(int a, int b) { int t = a; a = b; b = t; }

main has: Pt a = new Pt(1); move(a); reset(a); int u = 3, v = 8; swap(u, v);
(i) Find a.x. (1 mark)
(ii) Why does reset not change a? (1 mark)
(iii) Find u and v after swap and explain. (2 marks)

Try it first, then show the solutionSolution
  1. (i) move changes the shared object: a.x = 6. reset leaves it unchanged, so a.x = 6.
  2. (ii) reset assigns a new object to its own copy of the reference, p; the caller's a still refers to the old object.
  3. (iii) u = 3 and v = 8: swap exchanged only its local copies. Swapping needs the values in an array or object, or a return value.

Answer: (i) 6 (ii) the parameter p is a local copy of the reference, so reassigning it does not affect a (iii) u = 3, v = 8; primitives are passed by value

Where students lose marks in Methods, Arguments, Static Members and Method Overloading

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

  • Mistake: Expecting a primitive argument to change in the caller

    The method works on a copy of the value.

    Wrong working

    After change(x) with a = a + 10, x becomes 15

    Right working

    x stays unchanged

    Do this: Return the new value and assign it in the caller.

    Usually costs: 1 mark

  • Mistake: Using an instance variable in a static method

    A static method has no this and cannot see instance fields directly.

    Wrong working

    static int get() { return id; }

    Right working

    int get() { return id; }

    Do this: Make the method non-static or pass an object.

    Usually costs: 1 mark

  • Mistake: Overloading by return type only

    The compiler cannot choose between two methods with identical parameters.

    Wrong working

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

    Right working

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

    Do this: Change the number or types of parameters.

    Usually costs: 1 mark

Exam tips

  • Label formal and actual arguments when defining them.
  • Say "pass by value" and then explain what is copied: the value or the reference.
  • For static variable tracing draw one shared box and one box per object.
  • Show the full method header with return type and parameter types.
  • Give the output of the caller's variables after the call.

Practice questions on Methods, Arguments, Static Members and Method Overloading

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

    The keyword that refers to the current object inside an instance method is
    (a) super (b) static (c) this (d) final

    Hint

    It names the object that received the call.

    Answer

    (c) this

  2. Q2 · 2 marks · Short answerBoard level

    Distinguish between formal and actual arguments with an example.

    Hint

    Definition versus call.

    Answer

    In static int sq(int n) { return n * n; } the parameter n is the formal argument. In the call sq(7) the value 7 is the actual argument, and n receives a copy of 7.

  3. Q3 · 4 marks · Short answerHarder board level

    Write a method int hcf(int a, int b) using the Euclidean algorithm with a loop and trace it for hcf(12, 18).

    Hint

    Replace (a, b) by (b, a % b) until b is 0.

    Answer
    static int hcf(int a, int b) {
        while (b != 0) {
            int t = b;
            b = a % b;
            a = t;
        }
        return a;
    }

    Trace for (12, 18): t = 18, b = 12 % 18 = 12, a = 18; then t = 12, b = 18 % 12 = 6, a = 12; then t = 6, b = 12 % 6 = 0, a = 6. b is 0, so it returns 6.

  4. Q4 · 3 marks · Short answerHarder board level

    Write the output:

    class Demo {
        static int s = 0;
        int i = 0;
        void inc() { s++; i++; }
    }
    // in main
    Demo p = new Demo(), q = new Demo();
    p.inc(); p.inc(); q.inc();
    System.out.println(p.i + " " + q.i + " " + Demo.s);
    Hint

    One variable is shared, the other is per object.

    Answer

    p.inc() is called twice, so p.i = 2; q.inc() once, so q.i = 1. The shared s is incremented three times: 3. Output: 2 1 3

  5. Q5 · 4 marks · Case-basedHOTS / competency

    A method static void swap(int a, int b) exchanges its parameters. With x = 3 and y = 8, main calls swap(x, y) and prints x and y. (i) State the output and the reason. (ii) Write a method that works, using an int array {3, 8}, and give the output.

    Hint

    The array reference lets the method change shared data.

    Answer

    (i) 3 8: the method swaps copies of the values, so x and y are unchanged. (ii)

    static void swap(int[] v) {
        int t = v[0];
        v[0] = v[1];
        v[1] = t;
    }

    With int[] v = {3, 8}; swap(v); the array holds 8 and 3, so printing v[0] and v[1] gives 8 3.

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.What are the arguments in a method call called?Show answer

    Actual arguments.

  2. 2.What does a method receive when an array is passed?Show answer

    A copy of the reference to the same array.

  3. 3.How is a static method called?Show answer

    ClassName.methodName(arguments), without an object.

  4. 4.What is method overloading?Show answer

    Methods with the same name but different parameter lists.

  5. 5.Can a static method use this?Show answer

    No.

  6. 6.What does void mean in a method header?Show answer

    The method returns no value.

Methods, Arguments, Static Members and Method Overloading: frequently asked questions

Is Java pass by value or pass by reference?

Always pass by value: a primitive's value is copied, and for an object the reference is copied, which lets the method change the object but not the caller's reference.

What is the difference between a static and a non-static method?

A static method belongs to the class and is called without an object, while a non-static method acts on an object and can use this.

What is method overloading and why is it used?

It is defining several methods with the same name and different parameters, so one name can serve different kinds of input, such as area of a square, a rectangle or a circle.

Why is main declared static?

So the JVM can call it without creating an object of the class first.