ICSE · Class 10 · Computer Applications

Class 10 User-defined Methods Mock Test (ICSE)

6 practice questions from User-defined Methods, in the style of your board paper, each with a worked answer and the marks for every step. Then take a full chapter test on paper, snap the pages and get every step marked.

Topics in User-defined Methods

  • Method definition and prototype
  • Formal and actual parameters
  • Pure and impure methods
  • Call by value and call by reference
  • Method overloading
  • Static and non-static methods

User-defined Methods practice questions with answers

  1. Q1Multiple choice1 mark
    When a primitive data type is passed to a method as an argument, how is it passed in Java?
    1. (a)Call by reference
    2. (b)Call by address
    3. (c)Call by name
    4. (d)Call by value
    Show answer and step marks
    1. Correct option: (d) Call by value+1
    Answer: (d)
  2. Q2Multiple choice1 mark
    Which of the following forms a valid method prototype in Java?
    1. (a)compute(int a) : void
    2. (b)int compute[]
    3. (c)void compute a;
    4. (d)public void compute(int a)
    Show answer and step marks
    1. Correct option: (d) public void compute(int a)+1
    Answer: (d)
  3. Q3Multiple choice1 mark
    Which of the following best describes a pure method in Java?
    1. (a)It modifies the state of an object.
    2. (b)It does not return any value.
    3. (c)It uses static variables only.
    4. (d)It does not modify the object's state and returns a value.
    Show answer and step marks
    1. Correct option: (d) It does not modify the object's state and returns a value.+1
    Answer: (d)
  4. Q4Short answer2 marks
    What is meant by method overloading in Java? Can two methods be overloaded if they differ only in their return type? Give a reason.
    Show answer and step marks
    1. Method overloading means defining two or more methods with the same name in a class but with different parameter lists (different number, data types or order of parameters).+1
    2. No, two methods cannot be overloaded if they differ only in their return type.+0.5
    3. Reason: the compiler chooses between overloaded methods by their signature (name and parameter list), which does not include the return type, so such methods would clash and give a compile-time error.+0.5
    Answer: Method overloading is defining methods with the same name but different parameter lists. No: the return type is not part of the method signature the compiler uses to tell overloaded methods apart, so methods differing only in return type cause a compile-time error.
  5. Q5Short answer2 marks
    Explain the concept of method overloading in Java with a suitable example showing different parameter lists.
    Show answer and step marks
    1. Definition: method overloading is a feature where a class has two or more methods with the same name but different parameter lists (number, type or order of parameters).+1
    2. Example, any valid pair of same-name methods with different parameter lists, e.g. `void area(int s)` printing s×ss \times s for a square and `void area(int l, int b)` printing l×bl \times b for a rectangle.+1
    Answer: Method overloading: methods with the same name but different parameter lists in one class. Example: `void area(int s)` for a square and `void area(int l, int b)` for a rectangle.
  6. Q6Long answer4 marks
    Write a Java program using a class named `Calculator` that demonstrates the difference between static and non-static methods: 1. Define a static method `int add(int a, int b)` that returns the sum of two integers. 2. Define a non-static method `int multiply(int a, int b)` that returns the product of two integers. 3. In the `main` method, instantiate the class to invoke the non-static method and invoke the static method directly, displaying both results.
    Show answer and step marks
    1. Class header `class Calculator` and `public static void main(String args[])`.+1
    2. `static int add(int a, int b) { return a + b; }`.+1
    3. `int multiply(int a, int b) { return a × b; }` without the `static` keyword.+1
    4. In `main`: `add()` called directly (or as `Calculator.add()`), an object created with `new Calculator()` to call `multiply()`, and both results printed.+1
    Answer: class Calculator { static int add(int a, int b) { return a + b; } int multiply(int a, int b) { return a × b; } public static void main(String args[]) { int sum = add(6, 4); Calculator obj = new Calculator(); int product = obj.multiply(6, 4); System.out.println("Sum = " + sum); System.out.println("Product = " + product); } }

Take a full User-defined Methods test

PrepitUp writes a fresh paper on this chapter at the length you pick. Write it on paper with a timer, photograph the pages, and see the marks for every step and what to practise next.

  • 15 min10 marks
  • 30 min20 marks
  • 1.5 hr40 marks
  • 3 hr80 marks
See a sample marked answer sheet

Get your User-defined Methods answers marked

Sign in, pick this chapter and a length, write the test on paper and get every step marked.

Sign in to take this test

More Class 10 Computer Applications mock tests