Constructors in Java: ICSE Class 10 Notes with Types, Overloading and Programs
ICSE Class 10 Computer Applications notes on constructors: what a constructor is, default and parameterised constructors, constructor overloading, the this keyword, differences from methods, and solved programs.

Almost every class-based program in the ICSE Computer Applications board paper asks you to write a constructor, and 2-mark theory questions on constructors appear every year. These notes explain the chapter from scratch, with programs you can run in BlueJ.
What is a constructor?
A constructor is a special member method that initialises an object when it is created. It has three defining features:
- It has the same name as the class.
- It has no return type, not even
void. - It is called automatically when an object is created with
new.
class Book {
String title;
double price;
Book() { // constructor
title = "Untitled";
price = 0.0;
}
}
Book b = new Book(); // constructor runs automatically hereTypes of constructors
1. Default (non-parameterised) constructor
A default constructor takes no parameters and gives the data members starting values. If you do not write any constructor, Java supplies one automatically. That built-in constructor sets the data members to their default values: 0 for numbers, false for boolean, null for objects.
2. Parameterised constructor
A parameterised constructor receives values as parameters and uses them to initialise the object.
class Book {
String title;
double price;
Book(String t, double p) {
title = t;
price = p;
}
}
Book b = new Book("Java Basics", 250.0);Once you write a parameterised constructor, Java no longer supplies the default one.new Book()will then cause a compile error unless you also writeBook()yourself.
Constructor overloading
A class can have more than one constructor, as long as their parameter lists differ in the number, type or order of parameters. This is called constructor overloading.
class Rectangle {
int length, breadth;
Rectangle() { // default
length = breadth = 1;
}
Rectangle(int side) { // square
length = breadth = side;
}
Rectangle(int l, int b) { // rectangle
length = l;
breadth = b;
}
int area() {
return length * breadth;
}
}new Rectangle() gives area 1, new Rectangle(5) gives 25, and new Rectangle(4, 6) gives 24. Java chooses the constructor whose parameters match the arguments.
The this keyword
this refers to the current object. It is used when a parameter has the same name as a data member:
class Student {
String name;
int roll;
Student(String name, int roll) {
this.name = name; // this.name is the data member
this.roll = roll; // roll alone is the parameter
}
}Without this, name = name; would just assign the parameter to itself, and the data member would stay null.
Constructor vs method
- Name: a constructor has the same name as the class; a method can have any valid name.
- Return type: a constructor has none; a method must have one (or
void). - When it runs: a constructor runs automatically when an object is created; a method must be called explicitly.
- Purpose: a constructor initialises the object; a method performs an action.
Solved board-style program
Question: Define a class ElectricBill with the data members name and units and a parameterised constructor. A method calculate() computes the bill: ₹2 per unit for the first 100 units, ₹3 per unit for the next 200 units, and ₹5 per unit above 300 units. A method print() displays the details.
import java.util.Scanner;
class ElectricBill {
String name;
int units;
double bill;
ElectricBill(String n, int u) {
name = n;
units = u;
bill = 0.0;
}
void calculate() {
if (units <= 100)
bill = units * 2;
else if (units <= 300)
bill = 100 * 2 + (units - 100) * 3;
else
bill = 100 * 2 + 200 * 3 + (units - 300) * 5;
}
void print() {
System.out.println("Name: " + name);
System.out.println("Units: " + units);
System.out.println("Bill: Rs. " + bill);
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter name: ");
String n = sc.nextLine();
System.out.print("Enter units: ");
int u = sc.nextInt();
ElectricBill ob = new ElectricBill(n, u);
ob.calculate();
ob.print();
}
}Sample run: for 350 units, the bill is 200 + 600 + 250 = Rs. 1050.0.
Practice questions
- Can a constructor be declared
private? Can it return a value? - What happens if a class has only a parameterised constructor and you write
new ClassName()? - Write two overloaded constructors for a class
Circle: one with no parameters (radius 1) and one that takes the radius.
Answers:
- Yes, it can be private, which is used to restrict object creation. No, a constructor never returns a value.
- A compile-time error, because Java no longer supplies a default constructor.
Circle() { r = 1; }andCircle(double r) { this.r = r; }
Test yourself with our ICSE Class 10 MCQs on Methods and Constructors, which come with answers.
Related Posts
Continue learning with these related articles

Math Library Methods in Java for ICSE Class 9 (with Outputs)
ICSE Class 9 Computer Applications notes on the Java Math class: sqrt, cbrt, pow, abs, max, min, ceil, floor, round, rint and random, with return types, tricky negative-number outputs and Java expressions for formulas.

Loops in Java for ICSE Class 9: for, while, do-while and Nested Loops
ICSE Class 9 Computer Applications notes on loops in Java: for, while and do-while loops, entry vs exit control, break and continue, nested loops and pattern programs, with dry runs, output questions and solved programs.

Conditional Statements in Java: ICSE Class 9 Notes on if, if-else and switch
ICSE Class 9 Computer Applications notes on conditional statements in Java: if, if-else, if-else-if ladder, nested if, the ternary operator and switch-case with fall-through, with solved programs and output questions.