What is the difference between a default constructor and a parameterised constructor?
Last updated
A default constructor takes no arguments and initializes an object with default or predefined state, while a parameterised constructor accepts arguments to initialize an object with caller-supplied values.
Default constructor:
No parameters; sets fields to defaults (zero, null, or hard-coded values).
In many languages the compiler generates one automatically if you declare no constructor at all.
Parameterised constructor:
Takes one or more arguments to build an object in a specific, meaningful state.
Lets you enforce required fields at creation time so no object exists in an invalid state.
Key trap: Once you declare any parameterised constructor, the compiler stops auto-generating the default one; add it explicitly if you still need it.
[lang:java]
class Point {
int x, y;
Point() { this.x = 0; this.y = 0; } // default
Point(int x, int y) { this.x = x; this.y = y; } // parameterised
}