Skip to content
Computer ScienceISC Class 11 · Chapter 9

Methods and Constructors in Java: ISC Class 11 Notes

Updated 15 October 2026 · Fact-checked

A method is a named block of code that performs an operation, and a constructor is a special method that initialises a new object when it is created with new. ISC Class 11 Computer Science covers formal and actual arguments, primitive versus object arguments, side effects, static methods and variables, the this keyword, multiple constructors, and problem solving with methods.

What Methods and Constructors is about

Methods let you name a piece of work (find a root, test a prime, compute a distance) and reuse it. Constructors make sure every new object starts in a sensible state. Together they turn a long main method into a set of clear, testable building blocks.

The CISCE 2028 syllabus (Section B, topic 9) asks for: methods and constructors as abstractions for complex user-defined operations on objects; methods as mechanisms for side effects; formal and actual arguments; the different behaviour of primitive arguments; static methods and variables; the this operator; examples of algorithmic problem solving using methods (number problems, finding roots of algebraic equations); the main method; the constructor as a special kind of method; the new operator; and multiple constructors with different argument structures.

Four programs on this page were compiled and run: argument passing, a Point class with three constructors and a static counter, number tools built from small methods, and a bisection root finder.

Weightage: Methods and Constructors is topic 9 of the ISC Class XI Computer Science syllabus, in Section B - Java. CISCE weights Section B at 30 of the 70 marks in Paper I (Theory). Class XI is examined by the school, so your school sets the paper within this weightage.Source: CISCE ISC Computer Science syllabus, examination year 2028, Class XI unit weightage

Key concepts

Methods as abstractions; parts of a method

A method is a named, reusable block of statements that performs a task, may take inputs (parameters) and may return a result.

Why methods: abstraction (callers use isPrime(n) without knowing how it works); reuse (write once, call many times); modularity (break a big problem into small ones); easier testing and debugging.

Method header (prototype):

accessModifier [static] returnType methodName(type param1, type param2)

  • Access modifier: public, private, protected or default.
  • Return type: the type of value returned, or void if nothing is returned.
  • Signature: the method name plus the number, types and order of parameters (the return type is not part of the signature).

return ends the method and sends back a value (in a non-void method, every path must return a value of the right type).

Calling: obj.method(args) for instance methods; ClassName.method(args) for static methods; within the same class, just method(args).

Worked example

Write the header of a public method that takes a double radius and returns the area of a circle as a double, and give its signature. [2 marks]

Try it first, then show the solutionSolution
  1. Header: public double area(double radius).
  2. Signature: area(double).

Answer: public double area(double radius); signature area(double).

Formal and actual arguments; primitive vs object arguments; side effects

Formal arguments (parameters): variables in the method header that receive values (int m in addBonusPrimitive(int m)).

Actual arguments: the values or expressions supplied in the call (score in addBonusPrimitive(score)). They must match the formal arguments in number, order and compatible type.

Java passes arguments by value: the formal argument receives a copy of the actual argument's value.

  • Primitive argument: the method gets a copy of the number; changing the parameter does not change the caller's variable.
  • Object argument: the value copied is the reference, so the method can change the object's fields, and the caller sees the change (but assigning a new object to the parameter does not affect the caller's variable).

Pure method vs side effect: a pure method only computes and returns a result. A method with a side effect changes something outside itself: an object's state, a static variable, the screen or a file. Mutator methods (setters, deposit) work through side effects.

// Formal vs actual arguments; a primitive argument is copied, an object argument shares the object.
// Also a pure method (no side effect) and a method with a side effect.
public class Arguments
{
    int marks;

    Arguments(int m)
    {
        marks = m;
    }

    static int addBonusPure(int m, int bonus)      // pure: returns a result, changes nothing outside
    {
        return m + bonus;
    }

    static void addBonusPrimitive(int m)           // m is a copy of the caller's value
    {
        m = m + 5;
    }

    static void addBonusObject(Arguments s)        // s refers to the caller's object: side effect
    {
        s.marks = s.marks + 5;
    }

    public static void main(String[] args)
    {
        int score = 70;                            // actual argument
        System.out.println("pure result = " + addBonusPure(score, 5) + ", score still " + score);
        addBonusPrimitive(score);
        System.out.println("after addBonusPrimitive, score = " + score);

        Arguments st = new Arguments(70);
        addBonusObject(st);
        System.out.println("after addBonusObject, st.marks = " + st.marks);
    }
}

Output:

pure result = 75, score still 70
after addBonusPrimitive, score = 70
after addBonusObject, st.marks = 75

Worked example

After int p = 1, q = 2; swap(p, q); where swap exchanges its two int parameters, what are p and q? Why? [2 marks]

Try it first, then show the solutionSolution
  1. swap receives copies of 1 and 2 and exchanges the copies only.
  2. The caller's p and q are unchanged (an array or object argument would be needed to swap the caller's values).

Answer: p = 1, q = 2: primitive arguments are passed by value.

Constructors, the new operator and multiple constructors

A constructor is a special method that initialises a new object. It has the same name as the class, no return type (not even void), and is called automatically when an object is created with new.

The new operator: (1) allocates memory for the object; (2) gives fields default values; (3) calls the matching constructor; (4) returns the reference.

Types:

1. Default constructor: provided by Java automatically only if no constructor is written; it sets fields to default values (0, null, false).
2. Non-parameterised constructor: written by the programmer with no parameters.
3. Parameterised constructor: takes arguments to set the initial state.

Multiple constructors (constructor overloading): a class may have several constructors with different parameter lists (number, types or order); Java chooses one by matching the arguments. this(...) as the first statement of a constructor calls another constructor of the same class, avoiding repeated code.

Constructor vs method: constructor has the class's name and no return type, runs once per object at creation, cannot be called like an ordinary method; a method has a return type, any name, and can be called many times.

// Multiple constructors, the 'this' keyword, and static vs instance members.
public class Point
{
    private double x, y;               // instance variables: one copy per object
    static int created = 0;            // static (class) variable: one copy shared by all objects

    Point()                            // default constructor
    {
        this(0, 0);                    // calls the two-argument constructor
    }

    Point(double v)                    // a point on the line y = x
    {
        this(v, v);
    }

    Point(double x, double y)          // parameters have the same names as the fields
    {
        this.x = x;                    // 'this.x' is the field; 'x' is the parameter
        this.y = y;
        created++;
    }

    double distanceTo(Point p)
    {
        double dx = this.x - p.x, dy = this.y - p.y;
        return Math.sqrt(dx * dx + dy * dy);
    }

    static double distance(Point a, Point b)   // static: called on the class, no 'this'
    {
        return a.distanceTo(b);
    }

    public String toString()
    {
        return "(" + x + ", " + y + ")";
    }

    public static void main(String[] args)
    {
        Point o = new Point();
        Point d = new Point(2);
        Point q = new Point(6, 8);
        System.out.println(o + " " + d + " " + q);
        System.out.println("o to q = " + o.distanceTo(q));
        System.out.println("d to q = " + Point.distance(d, q));
        System.out.println("points created = " + Point.created);
    }
}

Output:

(0.0, 0.0) (2.0, 2.0) (6.0, 8.0)
o to q = 10.0
d to q = 7.211102550927978
points created = 3

Worked example

In Point, which constructor runs for new Point(2), and what are x and y? [1 mark]

Try it first, then show the solutionSolution
  1. Point(double v) matches one double argument; it calls this(v, v).

Answer: Point(double v), which calls Point(2, 2): x = 2.0, y = 2.0.

Static methods and variables; the this keyword

Instance members belong to each object: each Point has its own x and y; instance methods act on a particular object.

Static (class) members belong to the class as a whole:

  • A static variable has one copy shared by all objects (Point.created counts all points created).
  • A static method is called on the class (Point.distance(a, b), Math.sqrt(x)); it has no this, so it cannot use instance variables directly, only through an object reference.
  • main is static so the JVM can call it without creating an object.

The this keyword refers to the current object (the one whose method or constructor is running). Uses:

1. To refer to a field hidden by a parameter of the same name: this.x = x;.
2. To call another constructor of the same class: this(0, 0); (first statement only).
3. To pass the current object to another method, or return it.

this cannot be used in a static method, because there is no current object.

Worked example

In the Point program, why does Point.created show 3, and could distance() use x directly? [2 marks]

Try it first, then show the solutionSolution
  1. created is static: one shared counter incremented by the two-argument constructor, which runs (directly or through this) for each of the three points.
  2. distance() is static: it has no this, so it must use a.x or call a.distanceTo(b), not x alone.

Answer: 3, because the shared static counter increased once per object; a static method cannot refer to instance variables without an object reference.

Problem solving with methods: number problems

Break a problem into small methods, each doing one job, and combine them.

Example: emirps (primes whose reverse is a different prime, such as 13 and 31):

1. isPrime(n): trial division up to √n.
2. reverse(n): build the reversed number with % 10 and / 10.
3. isEmirp(n): isPrime(n) && isPrime(reverse(n)) && reverse(n) != n.

Each method is short and testable; isEmirp reads almost like its definition.

// Number problems solved with small static methods that call one another.
public class NumberTools
{
    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;
    }

    static int reverse(int n)
    {
        int r = 0;
        while (n > 0)
        {
            r = r * 10 + n % 10;
            n /= 10;
        }
        return r;
    }

    static boolean isEmirp(int n)              // prime whose reverse is a different prime
    {
        int r = reverse(n);
        return isPrime(n) && isPrime(r) && r != n;
    }

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

    public static void main(String[] args)
    {
        System.out.print("emirps below 100: ");
        for (int n = 2; n < 100; n++)
            if (isEmirp(n))
                System.out.print(n + " ");
        System.out.println();
        System.out.println("gcd(84, 120) = " + gcd(84, 120) + ", lcm = " + (84 * 120 / gcd(84, 120)));
    }
}

Output:

emirps below 100: 13 17 31 37 71 73 79 97 
gcd(84, 120) = 12, lcm = 840

Other number problems suited to methods: perfect numbers (sum of proper divisors), Armstrong numbers, digital root (repeat sum of digits until one digit), GCD and LCM, Fibonacci terms, palindromes.

Worked example

Using a method sumDigits(n), describe a method digitalRoot(n) and find the digital root of 98765. [2 marks]

Try it first, then show the solutionSolution
  1. digitalRoot: while n > 9, n = sumDigits(n); return n.
  2. 98765 → 9 + 8 + 7 + 6 + 5 = 35 → 3 + 5 = 8.

Answer: 8.

Finding roots of algebraic equations

Many equations (such as x³ − 2x − 5 = 0) have no simple formula for their roots, so we find them numerically with methods.

Bisection method: if f(lo) and f(hi) have opposite signs, a root lies between them.

1. mid = (lo + hi) / 2.
2. If f(lo) × f(mid) ≤ 0, the root is in [lo, mid]: set hi = mid; otherwise set lo = mid.
3. Repeat until hi − lo is smaller than the tolerance.

Each step halves the interval, so starting with width 1 and tolerance 0.0001 needs 14 steps (2¹⁴ = 16,384 > 10,000).

Newton-Raphson method (faster, needs the derivative): xₙ₊₁ = xₙ − f(xₙ) ÷ f'(xₙ). For √a, solving x² − a = 0 gives xₙ₊₁ = (xₙ + a ÷ xₙ) ÷ 2.

// Algorithmic problem solving with methods: root of an algebraic equation by bisection.
public class Roots
{
    static double f(double x)                 // the equation f(x) = 0: x^3 - 2x - 5
    {
        return x * x * x - 2 * x - 5;
    }

    static double bisect(double lo, double hi, double tol)
    {
        int steps = 0;
        while (hi - lo > tol)
        {
            double mid = (lo + hi) / 2;
            if (f(lo) * f(mid) <= 0)          // sign change in the left half
                hi = mid;
            else
                lo = mid;
            steps++;
        }
        System.out.println("steps = " + steps);
        return (lo + hi) / 2;
    }

    public static void main(String[] args)
    {
        System.out.println("f(2) = " + f(2) + ", f(3) = " + f(3));
        double r = bisect(2, 3, 0.0001);
        System.out.println("root = " + Math.round(r * 10000) / 10000.0);
    }
}

Output:

f(2) = -1.0, f(3) = 16.0
steps = 14
root = 2.0946

f(2) = −1 and f(3) = 16 have opposite signs, so a root lies in [2, 3]; bisection finds 2.0946.

Worked example

Show one bisection step for f(x) = x³ − 2x − 5 starting with [2, 3]. [2 marks]

Try it first, then show the solutionSolution
  1. mid = 2.5; f(2.5) = 15.625 − 5 − 5 = 5.625 (positive); f(2) = −1 (negative).
  2. Signs differ in [2, 2.5]: new interval [2, 2.5].

Answer: f(2.5) = 5.625 > 0, so the root lies in [2, 2.5].

Methods and Constructors 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.

Methods as reusable tools

Suppose a school app needs to check whether a roll number is valid in five different screens.

Why write a method isValidRoll(int r) instead of repeating the check?

Try it first, then show the solutionSolution
  1. Write the rule once and call it from all five screens.
  2. If the rule changes, only the method changes.

Answer: Reuse and easy maintenance: one tested method serves every screen.

Memory hook: Write once, call everywhere.

Constructor sets the start

Imagine opening a new bank account: the bank records your name and opening deposit at the moment the account is created.

Which Java feature models this?

Try it first, then show the solutionSolution
  1. A constructor runs automatically when new creates the object.
  2. A parameterised constructor BankAccount(String name, double opening) sets the starting state.

Answer: A parameterised constructor called by new.

Memory hook: Born with a name and a balance.

Static counters

Suppose a ticket machine prints a serial number on each ticket, continuing across all machines in a station.

Should the serial counter be static or an instance variable in a Ticket class?

Try it first, then show the solutionSolution
  1. The counter must be shared by every ticket, not stored separately in each.
  2. A static variable has exactly one copy for the whole class.

Answer: Static: one shared counter incremented by the constructor for each new ticket.

Memory hook: Shared by all → static.

Topics in this chapter

Methods and Constructors: syntax and key facts

Method header
access [static] returnType name(type p1, type p2, ...)
Signature = name + parameter list.
Object creation
ClassName ref = new ClassName(args); → memory, defaults, constructor, reference
Bisection step
mid = (lo + hi) / 2; if f(lo) × f(mid) ≤ 0 then hi = mid else lo = mid
Steps ≈ log₂(initial width ÷ tolerance).
Newton-Raphson
xₙ₊₁ = xₙ − f(xₙ) ÷ f'(xₙ); for √a: xₙ₊₁ = (xₙ + a ÷ xₙ) ÷ 2
this
this.field = parameter; this(args) must be the first statement of a constructor

Methods and Constructors: diagrams to practise

Practise each one on paper: draw it from the checklist, then tick off every label.

Call and return

Explain how a method call works with arguments.

Draw

  1. Box 'main' with score = 70 and a call addBonusPure(score, 5).
  2. Arrow to box 'addBonusPure' with formal parameters m = 70, bonus = 5 (copies).
  3. Return arrow carrying 75 back to main; score in main still 70.

Label

  • actual arguments
  • formal parameters
  • return value

Watch out: Show copies explicitly to explain why primitives are not changed by the method.

Static vs instance members

Distinguish static and instance variables.

Draw

  1. One box 'class Point' holding created = 3.
  2. Three object boxes o, d, q, each with its own x and y, all with arrows to the shared created box.

Label

  • class (static)
  • objects (instance)
  • shared copy

Watch out: One static box shared by many object boxes is the key picture.

How the school exam asks Methods and Constructors

The question patterns to expect, and the method that works for each.

Question typeHow it is askedMethod
Theory (1-2 marks)Formal vs actual arguments; constructor vs method; uses of this; static vs instance; signature.Short definitions with a header or a call as an example.
Output and tracing (2-5 marks)Trace argument passing (primitive vs object), constructor chaining with this, static counters, bisection steps.Track copies vs references; note which constructor is matched.
Class design (10 marks)Design a class with data members, several constructors and methods for a number or geometry problem, with main.Follow the given names and signatures exactly; small methods that call each other.

Tricks to remember Methods and Constructors

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

  • Constructor: same name, no return

    If it has a return type, it is a method, not a constructor.

    Use it when: Recognising constructors.

  • Primitives copy, objects share

    Copy the number; share the object (through a copied reference).

    Use it when: Argument passing.

  • this = me

    this.x is my x; this(...) calls my other constructor.

    Use it when: The this keyword.

  • Static = class-wide, no this

    Static belongs to the class; it cannot see 'me'.

    Use it when: Static members.

Methods and Constructors: exam-level solved questions

Ordered from exam level to HOTS. Cover the solution, write your own, then compare step by step.

Example 1: Constructor rules · 1 mark · MCQExam level

Which statement about constructors is true?
(a) A constructor must return void.
(b) A constructor has the same name as its class and no return type.
(c) A class can have only one constructor.
(d) A constructor must be static.

Try it first, then show the solutionSolution
  1. Constructors share the class name and have no return type; they can be overloaded.

Answer: (b).

Example 2: Static methods and this · 1 mark · Assertion-reasonHarder exam level

Assertion: A static method cannot use this.
Reason: A static method belongs to the class and is not called on any particular object.
(a) Both Assertion and Reason are true and Reason is the correct explanation of Assertion.
(b) Both Assertion and Reason are true but Reason is not the correct explanation of Assertion.
(c) Assertion is true but Reason is false.
(d) Both Assertion and Reason are false.

Try it first, then show the solutionSolution
  1. this refers to the current object; a static method has none: the Reason explains the Assertion.

Answer: (a)

Example 3: Primitive and object arguments · 2 marks · Short answerExam level

In the Arguments program, why does score stay 70 after addBonusPrimitive(score) while st.marks becomes 75 after addBonusObject(st)?

Try it first, then show the solutionSolution
  1. addBonusPrimitive gets a copy of 70; adding 5 to the copy does not touch score.
  2. addBonusObject gets a copy of the reference to the same object, so s.marks += 5 changes that object.

Answer: Primitives are passed as value copies; objects are reached through a copied reference, so their fields can be changed (a side effect).

Example 4: Overloading and this() · 5 marks · Short answerHarder exam level

For class Point with constructors Point(), Point(double v) and Point(double x, double y), explain constructor overloading and this(...). What do new Point() and new Point(3, 4) produce, what is their distance, and what is Point.created after creating these two objects in a fresh program?

Try it first, then show the solutionSolution
  1. Overloading: several constructors with different parameter lists; Java picks the one whose parameters match the arguments.
  2. Point() calls this(0, 0); Point(double v) calls this(v, v); both reuse the two-argument constructor.
  3. new Point() → (0.0, 0.0); new Point(3, 4) → (3.0, 4.0).
  4. Distance = √(3² + 4²) = 5.0.
  5. created is incremented once per object (in the two-argument constructor): 2.

Answer: Points (0.0, 0.0) and (3.0, 4.0); distance 5.0; created = 2 (the compiled check printed 5.0 2).

Example 5: Bisection by hand · 5 marks · Short answerHOTS / competency

Perform three bisection steps for f(x) = x³ − 2x − 5 on [2, 3], and state how many steps are needed for a tolerance of 0.0001.

Try it first, then show the solutionSolution
  1. Step 1: mid 2.5, f = 5.625 > 0 → [2, 2.5].
  2. Step 2: mid 2.25, f = 11.390625 − 4.5 − 5 = 1.890625 > 0 → [2, 2.25].
  3. Step 3: mid 2.125, f = 9.595703125 − 4.25 − 5 = 0.345703125 > 0 → [2, 2.125].
  4. Width after n steps = 1 ÷ 2ⁿ < 0.0001 needs 2ⁿ > 10,000, so n = 14.
  5. The compiled Roots program reports 14 steps and root 2.0946.

Answer: Intervals [2, 2.5], [2, 2.25], [2, 2.125]; 14 steps; root ≈ 2.0946.

Example 6: Emirp program · 10 marks · Long answerHOTS / competency

Write a class with static methods boolean isPrime(int n), int reverse(int n) and boolean isEmirp(int n), and a main() that prints all emirps below 100. Explain how the methods work together.

Try it first, then show the solutionSolution
  1. isPrime: return false for n < 2; for i from 2 while i × i ≤ n, return false if n % i == 0; return true.
  2. reverse: r = r × 10 + n % 10, n /= 10, while n > 0.
  3. isEmirp: r = reverse(n); return isPrime(n) && isPrime(r) && r != n (palindromic primes such as 11 are excluded).
  4. main: loop n from 2 to 99 and print n when isEmirp(n) is true.
  5. Methods are static because they need no object state.
  6. Output (compiled NumberTools program): 13 17 31 37 71 73 79 97.

Answer: See the compiled NumberTools program in the number-problems section; emirps below 100 are 13, 17, 31, 37, 71, 73, 79 and 97.

Case-study practice (Section D style)

Read the situation, then answer every part. In a school exam set on the board pattern this is a 5-mark question split into 2 + 2 + 1 marks.

Library fine calculator

Suppose a class Loan has fields bookId (String), daysLate (int) and a static variable totalFines (double). It has constructors Loan(String id) (on time) and Loan(String id, int late). A method double fine() returns ₹2 per day for the first 7 late days and ₹5 per day after that, and adds the fine to totalFines.

  1. (i) · 2 marks

    Write the second constructor using this.

    Answer

    Answer: Loan(String bookId, int daysLate) { this.bookId = bookId; this.daysLate = daysLate; } and Loan(String id) { this(id, 0); }

    1 mark each constructor.

  2. (ii) · 2 marks

    Calculate the fine for 5 days and for 12 days late.

    Answer

    Answer: 5 days: 5 × 2 = ₹10. 12 days: 7 × 2 + 5 × 5 = 14 + 25 = ₹39.

    1 mark each.

  3. (iii) · 1 mark

    Why is totalFines static, and which method has a side effect?

    Answer

    Answer: It must be one shared total for all loans; fine() has a side effect because it changes totalFines as well as returning a value.

    1 mark.

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.

Primitive vs object arguments (2 marks) (2 marks)

StepMarks
Copy of a primitive explained1
Shared object through a copied reference explained1

Constructor overloading and this() (5 marks) (5 marks)

StepMarks
Meaning of overloading1
this(...) chaining explained1
Objects produced1
Distance1
Static counter value1

Emirp program (10 marks) (10 marks)

StepMarks
isPrime3
reverse2
isEmirp combining both and excluding palindromes2
main loop and output2
Explanation of method use1

Where students lose marks in Methods and Constructors

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

  • Mistake: Giving a constructor a return type

    void Point() is an ordinary method, not a constructor; it will not run on new.

    Do this: No return type at all for constructors.

    Usually costs: 1-2 marks.

  • Mistake: Expecting a method to change a primitive argument

    Primitives are passed by value; return the new value instead.

    Do this: score = addBonusPure(score, 5);

    Usually costs: 1 mark.

  • Mistake: Using instance variables directly in a static method

    Static methods have no current object.

    Do this: Use an object reference, or make the method an instance method.

    Usually costs: 1 mark.

  • Mistake: Putting this(...) after other statements

    A constructor call with this must be the first statement.

    Do this: Move this(...) to the first line.

    Usually costs: 1 mark.

Practice questions on Methods 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 · MCQExam level

    The variables in a method's header that receive values are called:
    (a) actual arguments
    (b) formal arguments
    (c) static variables
    (d) constants

    Hint

    In the header.

    Answer

    (b) formal arguments.

  2. Q2 · 1 mark · Very short answerExam level

    When does Java provide a default constructor?

    Hint

    Only if...

    Answer

    Only when the class defines no constructor at all.

  3. Q3 · 2 marks · Short answerExam level

    State two differences between a constructor and a method.

    Hint

    Name, return type, calling.

    Answer

    A constructor has the class's name and no return type; a method has any name and a return type (or void). A constructor runs automatically once when an object is created with new; a method is called explicitly, any number of times.

  4. Q4 · 2 marks · Short answerHarder exam level

    Write overloaded static methods volume(double side) for a cube and volume(double l, double b, double h) for a cuboid, and give volume(3) and volume(2, 3, 4).

    Hint

    Different parameter lists.

    Answer

    static double volume(double side) { return side * side * side; } static double volume(double l, double b, double h) { return l * b * h; } Results: 27.0 and 24.0.

  5. Q5 · 2 marks · Short answerHarder exam level

    Give three uses of the this keyword.

    Hint

    Field, constructor, current object.

    Answer

    To refer to a field hidden by a parameter (this.x = x); to call another constructor of the same class (this(0, 0)); to pass or return the current object (return this; or other.compare(this)).

  6. Q6 · 2 marks · Short answerHarder exam level

    Write a method that swaps the two elements of an int array of length 2, and explain why it works when swapping two int variables does not.

    Hint

    Arrays are objects.

    Answer

    static void swapArr(int[] v) { int t = v[0]; v[0] = v[1]; v[1] = t; } The array is an object; the method receives a copy of its reference and changes the caller's array elements, so {1, 2} becomes {2, 1}. Two int variables are passed as copies, which the method cannot change.

  7. Q7 · 5 marks · Short answerHOTS / competency

    Write a method double newtonSqrt(double a) using six Newton-Raphson iterations starting from x = a, and give the result for a = 10 to five decimal places.

    Hint

    x = (x + a / x) / 2.

    Answer

    static double newtonSqrt(double a) { double x = a; for (int i = 0; i < 6; i++) x = (x + a / x) / 2; return x; } For a = 10 it gives 3.16228 (√10 = 3.162277...).

  8. Q8 · 2 marks · Short answerHarder exam level

    Distinguish between static and instance variables with an example of each in a class Student.

    Hint

    One copy vs one per object.

    Answer

    An instance variable has a separate copy in each object (String name; each student has their own). A static variable has one copy shared by all objects of the class (static int count; the total number of Student objects created).

  9. Q9 · 10 marks · Long answerHOTS / competency

    Design a class Fraction with constructors Fraction() (0/1), Fraction(int n) (n/1) and Fraction(int n, int d) that stores the fraction in lowest terms using a private gcd method; a static variable counting fractions created; and an instance method Fraction multiply(Fraction f). Give the result of (2/3) × (9/4) and the count after creating these two and the product.

    Hint

    Chain constructors with this; reduce by gcd.

    Answer

    Fields int num, den; static int count. Fraction() { this(0, 1); } Fraction(int n) { this(n, 1); } Fraction(int n, int d) { int g = gcd(Math.abs(n), Math.abs(d)); if (g == 0) g = 1; num = n / g; den = d / g; count++; } private static int gcd(int a, int b) { while (b != 0) { int t = a % b; a = b; b = t; } return a; } Fraction multiply(Fraction f) { return new Fraction(num * f.num, den * f.den); } (2/3) × (9/4) = 18/12 = 3/2; count = 3 (two operands and the product).

  10. Q10 · 2 marks · Short answerHOTS / competency

    Why is main declared static, and what would happen if it were not?

    Hint

    No object exists at start.

    Answer

    When the program starts, no object of the class exists, so the JVM calls main on the class itself; this requires main to be static. If it were not static, the java launcher (in every version before Java 25) refuses to start the program and reports that main must be declared public static void main(String[] args). Java 25 added instance main methods, for which the launcher first creates an object, but ISC answers should use the standard static form.

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.Return type of a constructor?Show answer

    None (not even void).

  3. 3.How are primitives passed?Show answer

    By value (a copy).

  4. 4.Static variable copies?Show answer

    One, shared by all objects.

  5. 5.this(...) placement?Show answer

    First statement of a constructor.

  6. 6.Bisection halves?Show answer

    The interval containing the root at each step.

Best order to study it

  1. Methods as abstractions; header, signature, return.
  2. Formal and actual arguments; primitives vs objects; side effects.
  3. Constructors, new, default and parameterised constructors.
  4. Multiple constructors and this(...).
  5. Static vs instance members; this.
  6. Problem solving: number methods and roots of equations.

Quick revision checklist

The night before the exam: can you do each of these without looking?

  • Method: named reusable block; header = access, static?, return type, name, parameters.
  • Formal (header) vs actual (call) arguments; pass by value.
  • Primitive copy unchanged; object fields can change (side effect).
  • Constructor: class name, no return type, runs on new; overload with different parameter lists; this(...) first.
  • static: class-wide, no this; main is static.
  • Bisection: halve the sign-change interval; Newton: x − f/f'.

Methods and Constructors: frequently asked questions

Does Java pass objects by reference?

Java always passes by value. For objects, the value passed is a copy of the reference, so the method can change the object's fields, but reassigning the parameter does not affect the caller's variable.

Can a constructor call a method?

Yes. A constructor can call methods of the class (for example a private gcd method) to help initialise the object.

Why use methods for finding roots?

Writing f(x) as its own method lets the same bisection (or Newton) method solve different equations by changing only f, which is clearer and less error-prone.

Based on: CISCE ISC 2028 Computer Science syllabus (Classes XI and XII); CISCE Regulations for the ISC Examination Year 2028 (Class XI internal examination)