ICSE · Class 10 · Computer Applications
Class 10 Constructors Mock Test (ICSE)
6 practice questions from Constructors, 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 Constructors
- Purpose of a constructor
- Default and parameterised constructors
- Constructor overloading
- this keyword
- Difference between constructor and method
Constructors practice questions with answers
- Q1Multiple choice1 markWhich of the following statements correctly distinguishes how a constructor is invoked compared to a normal member method in Java?
- (a)A constructor is invoked explicitly using an object reference followed by the dot operator, whereas a method is called implicitly using the new keyword.
- (b)A constructor is invoked automatically by the system using the new operator when an object is created, whereas a method is called explicitly using an object reference and the dot operator.
- (c)Both constructors and methods are invoked automatically whenever a class is loaded into the memory.
- (d)A constructor can be called at any point during the execution of a program on an existing object, whereas a method is restricted to execution only during object instantiation.
Show answer and step marks
- Correct option: (b) A constructor is invoked automatically by the system using the new operator when an object is created, whereas a method is called explicitly using an object reference and the dot operator.+1
Answer: (b) - Q2Multiple choice1 markConsider a class `Demo` that has a parameterised constructor defined, but no explicit default constructor. Which of the following is true?
- (a)The class will fail to compile altogether.
- (b)Creating an object using `Demo obj = new Demo();` will result in a compilation error.
- (c)The compiler automatically provides a default constructor.
- (d)The parameterised constructor acts as a default constructor.
Show answer and step marks
- Correct option: (b) Creating an object using Demo obj = new Demo(); will result in a compilation error.+1
Answer: (b) - Q3Multiple choice1 markWhat is constructor overloading in Java?
- (a)Inheriting constructors from a parent class.
- (b)Defining multiple constructors in a class with the same name but different parameter lists.
- (c)Defining multiple constructors in a class with different names.
- (d)Defining multiple constructors in a class with the same name and the same parameter list.
Show answer and step marks
- Correct option: (b) Defining multiple constructors in a class with the same name but different parameter lists.+1
Answer: (b) - Q4Short answer2 marksState the purpose of the `this` keyword in Java constructors. Give a brief example of its usage.
Show answer and step marks
- Purpose: `this` refers to the current object (the object whose constructor is running); in a constructor it is used to tell an instance variable apart from a parameter or local variable with the same name.+1
- Example: `class Point { int x; Point(int x) { this.x = x; } }`, where `this.x` is the instance variable and `x` is the parameter.+1
Answer: `this` refers to the current object; in a constructor it separates instance variables from parameters with the same name. Example: `Point(int x) { this.x = x; }` assigns the parameter `x` to the instance variable `x`. - Q5Long answer4 marksDesign a class named `Book` with the following specifications: **Data members:** - `String title` - to store the book title - `double price` - to store the book price **Member Methods / Constructors:** - `Book()` - A default constructor to initialize `title` to `"Unspecified"` and `price` to `0.0`. - `Book(String t, double p)` - A parameterised constructor to initialize `title` to `t` and `price` to `p`. - `void display()` - To display the book details. Write the complete Java class with a `main` method to create two objects—one using the default constructor and another using the parameterised constructor—and call their `display()` method.
Show answer and step marks
- Class declaration `class Book` with data members `String title; double price;`.+0.5
- Default constructor `Book() { title = "Unspecified"; price = 0.0; }` with no return type.+1
- Parameterised constructor `Book(String t, double p) { title = t; price = p; }`.+1
- `void display()` printing the title and the price.+0.5
- `main` creating one object with `new Book()` and another with `new Book(...)` with two arguments, and calling `display()` on each.+1
Answer: class Book { String title; double price; Book() { title = "Unspecified"; price = 0.0; } Book(String t, double p) { title = t; price = p; } void display() { System.out.println("Title: " + title); System.out.println("Price: " + price); } public static void main(String args[]) { Book b1 = new Book(); Book b2 = new Book("Java Basics", 350.0); b1.display(); b2.display(); } } - Q6Long answer4 marksWrite a Java class named `Rectangle` with the following specifications: - Data members: `double length`, `double breadth` - Parameterised constructor: `Rectangle(double l, double b)` to initialize the data members. - Member method: `void computeArea()` to calculate and print the area of the rectangle. Further, state any two differences between a constructor and a method in Java.
Show answer and step marks
- Class declaration `class Rectangle` with data members `double length, breadth;`.+1
- Parameterised constructor `Rectangle(double l, double b) { length = l; breadth = b; }`.+1
- `void computeArea()` computing `length × breadth` and printing the area.+1
- First difference, any one of: a constructor has the same name as the class, a method can have any name; a constructor has no return type (not even `void`), a method has a return type or `void`; a constructor is called automatically when an object is created with `new`, a method is called explicitly through an object or the class; a constructor initialises the object, a method performs a task or operation; or any other valid difference.+0.5
- Second difference, a different one from the same list.+0.5
Answer: class Rectangle { double length, breadth; Rectangle(double l, double b) { length = l; breadth = b; } void computeArea() { double area = length × breadth; System.out.println("Area of the rectangle = " + area); } } Any two differences: a constructor has the same name as the class, a method any name; a constructor has no return type, a method has one (or void); a constructor is called automatically on object creation, a method explicitly; a constructor initialises the object, a method performs a task.
Take a full Constructors 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 Constructors 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