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
- Q1Multiple choice1 markWhen a primitive data type is passed to a method as an argument, how is it passed in Java?
- (a)Call by reference
- (b)Call by address
- (c)Call by name
- (d)Call by value
Show answer and step marks
- Correct option: (d) Call by value+1
Answer: (d) - Q2Multiple choice1 markWhich of the following forms a valid method prototype in Java?
- (a)compute(int a) : void
- (b)int compute[]
- (c)void compute a;
- (d)public void compute(int a)
Show answer and step marks
- Correct option: (d) public void compute(int a)+1
Answer: (d) - Q3Multiple choice1 markWhich of the following best describes a pure method in Java?
- (a)It modifies the state of an object.
- (b)It does not return any value.
- (c)It uses static variables only.
- (d)It does not modify the object's state and returns a value.
Show answer and step marks
- Correct option: (d) It does not modify the object's state and returns a value.+1
Answer: (d) - Q4Short answer2 marksWhat 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
- 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
- No, two methods cannot be overloaded if they differ only in their return type.+0.5
- 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. - Q5Short answer2 marksExplain the concept of method overloading in Java with a suitable example showing different parameter lists.
Show answer and step marks
- 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
- Example, any valid pair of same-name methods with different parameter lists, e.g. `void area(int s)` printing for a square and `void area(int l, int b)` printing 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. - Q6Long answer4 marksWrite 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
- Class header `class Calculator` and `public static void main(String args[])`.+1
- `static int add(int a, int b) { return a + b; }`.+1
- `int multiply(int a, int b) { return a × b; }` without the `static` keyword.+1
- 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
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