Constructors
ICSE Class 10 · Computer Applications · Chapter 4
What this chapter covers
- Definition of a constructor
- Characteristics of constructors
- Use of constructors
- Types of constructors
- Default constructor
- Parameterised constructor
- Constructor overloading
- Difference between a constructor and a method
Key points
- A constructor is a special member with the class's name and no return type, run automatically when `new` creates an object.
- Its use is to initialise the instance variables so that no object exists in a half-ready state.
- A constructor runs once per object, cannot be `static`, is not inherited, and is not called with dot notation.
- Writing `void` before a constructor's name turns it into an ordinary method.
- The default constructor takes no parameters; the compiler supplies one only when the class has no constructor at all.
- The compiler-supplied default constructor leaves instance variables at 0, 0.0, `false`, `'\u0000'` or `null`.
- A parameterised constructor receives arguments and copies them into the instance variables; arguments must match in number, type and order.
- Constructor overloading means several constructors in one class with different parameter lists (number, type or order of parameters).
- The compiler chooses which overloaded constructor to run by matching the arguments after `new`.
- A constructor differs from a method in name, return type, purpose, invocation, number of executions and compiler support.
Questions answered
Define a constructor.
Why does a constructor have no return type?
State any four characteristics of a constructor.
Name the two types of constructors in the syllabus and state one difference between them.
What does the compiler-supplied default constructor store in an `int`, a `double`, a `boolean` and a `String` instance variable?
A class has only the constructor `Car(String m)`. Will `Car c = new Car();` compile? Give a reason.
What is constructor overloading? State the three ways in which overloaded constructors may differ.
Can `Shape(int a)` and `Shape(int b)` exist in the same class? Why?
Past board exam questions
ICSE 2026 board paper · 1 mark
In constructor overloading all constructors should have the same name as of the class but with a different set of ____________.
- Access specifiers
- Classes
- Return type
- Parameters
Show answer
ICSE 2025 board paper · 2 marks
Write the Java statement for creating an object named ‘sifra’ of the class ‘Robot’, which takes three double parameters.
Show answer
ICSE 2025 sample paper · 2 marks
Consider the following program segment and answer the questions below: ``` class calculate { int a; double b; calculate() { a=0; b=0.0; } calculate(int x, double y) { a=x; b=y; } void sum() { System.out.println(a*b); }} ``` Name the type of constructors used in the above program segment?
Show answer
ICSE 2025 board paper · 2 marks
Consider and give the output of the following program: class report { int a,b; report() { a=10; b=15; } report(int x, int y) { a=x; b=y; } void print() { System.out.println(a*b); } static void main() { report r = new report(); r.print(); report p = new report(4, 5); p.print(); } }
Show answer
ICSE 2025 compartment paper · 2 marks
class perform { int m ; String name; perform( int x , String y) { m=x; name=y; } void print () { System.out.print( name+" "+m); } public static void main( ) { perform ob1=new perform( 95 , "Xavier"); ob1.print( ); } } (a) Give the output of the code given above. (b) Name the type of the constructor used.
Show answer
ICSE 2024 sample paper · 1 mark
Constructor overloading follows which principle of Object Oriented programming?
- Inheritance
- Polymorphism
- Abstraction
- Encapsulation
Show answer
ICSE 2024 board paper · 1 mark
If the name of the class is “Yellow”, what can be the possible name for its constructors?
- yellow
- YELLOW
- Yell
- Yellow
Show answer
ICSE 2024 board paper · 2 marks
Consider the given program and answer the questions given below: class temp { int a; temp() { a=10; } temp(int z) { a=z; } void print() { System.out.println(a); } void main() { temp t = new temp(); temp x = new temp(30); t.print(); x.print(); } } (a) What concept of OOPs is depicted in the above program with two constructors? (b) What is the output of the method main()?