Free tutorials & notes in Hindi & English · Clean code examples · Mobile friendly learning
Free tutorials in Hindi & English Daily computer, mobile and IT guides Beginner friendly learning
Blog · Java · 04 Jul 2026 · Hindi + English

Java में Constructor: Types, Rules और Examples

Constructor objects को initialize करता है और new के साथ automatically चलता है. Default, parameterized और copy constructors, overloading और rules सीखें.

What is a constructor?

A constructor is a special method that runs automatically when an object is created with new. Its job: initialize the object's variables. Two identity rules: same name as the class and no return type (not even void).
class Student {
    String name;
    int marks;

    Student(String n, int m) {   // constructor: class name, no return type
        name = n;
        marks = m;
    }
}

Student s1 = new Student("Aman", 92);   // constructor runs HERE

Type 1: Default constructor

class Book {
    String title = "Untitled";
    // no constructor written -> Java silently adds: Book() { }
}
Book b = new Book();        // works because of the invisible default
The classic trap: Java adds the default constructor only if you wrote none. The moment you write any parameterized constructor, the default disappears — and old new Book() calls break with "constructor Book() is undefined". Asked in almost every Java interview.

Type 2: Parameterized constructor

class Student {
    String name; int marks;

    Student(String n, int m) {
        name = n; marks = m;
    }
}
Student s = new Student("Priya", 88);
System.out.println(s.name + " " + s.marks);
Priya 88

Constructor overloading + this()

class Student {
    String name; int marks;

    Student() {                    // no-arg version
        this("Unknown", 0);        // calls the 2-arg constructor
    }
    Student(String n, int m) {
        name = n; marks = m;
    }
}

Student a = new Student();
Student b = new Student("Rahul", 95);
System.out.println(a.name + " | " + b.name);
Unknown | Rahul

Multiple constructors with different parameter lists = overloading. this(...) chains one constructor to another and must be the first statement.

Constructor vs method (exam table)

PointConstructorMethod
NameMust equal class nameAny name
Return typeNone (not even void)Required
CalledAutomatically by newExplicitly by you
InheritedNoYes
PurposeInitialize objectPerform behaviour

Constructor क्या है?

Constructor एक special method है जो new से object बनते ही automatically चलता है. काम: object के variables initialize करना. दो पहचान rules: class के same नाम और कोई return type नहीं (void भी नहीं).
class Student {
    String name;
    int marks;

    Student(String n, int m) {   // constructor: class name, no return type
        name = n;
        marks = m;
    }
}

Student s1 = new Student("Aman", 92);   // constructor YAHAN chala

Type 1: Default constructor

class Book {
    String title = "Untitled";
    // कोई constructor नहीं लिखा -> Java चुपचाप जोड़ता है: Book() { }
}
Book b = new Book();        // invisible default की वजह से चलता है
Classic trap: Java default constructor तभी जोड़ता है जब आपने कोई नहीं लिखा. जैसे ही कोई parameterized constructor लिखा, default गायब — और पुराने new Book() calls "constructor Book() is undefined" से टूट जाते हैं. लगभग हर Java interview में पूछा जाता है.

Type 2: Parameterized constructor

class Student {
    String name; int marks;

    Student(String n, int m) {
        name = n; marks = m;
    }
}
Student s = new Student("Priya", 88);
System.out.println(s.name + " " + s.marks);
Priya 88

Constructor overloading + this()

class Student {
    String name; int marks;

    Student() {                    // no-arg version
        this("Unknown", 0);        // 2-arg constructor को call
    }
    Student(String n, int m) {
        name = n; marks = m;
    }
}

Student a = new Student();
Student b = new Student("Rahul", 95);
System.out.println(a.name + " | " + b.name);
Unknown | Rahul

अलग parameter lists वाले multiple constructors = overloading. this(...) एक constructor को दूसरे से chain करता है और पहला statement होना ज़रूरी है.

Constructor vs method (exam table)

PointConstructorMethod
NameClass name के बराबरकोई भी नाम
Return typeनहीं (void भी नहीं)ज़रूरी
Callnew से automaticallyआप explicitly करते हैं
Inherit होता हैनहींहां
PurposeObject initializeBehaviour perform

Frequently Asked Questions

Java में constructor क्या है?

Constructor class के same नाम और बिना return type वाला special method है, जो new से object बनते ही automatically चलता है और object को initialize करता है.

अपना constructor लिखने पर default constructor का क्या होता है?

Java invisible default constructor तभी देता है जब कोई constructor न लिखा हो; कोई भी constructor जोड़ते ही default गायब हो जाता है और no-arg creation fail होता है जब तक आप उसे वापस न जोड़ें.

क्या Java में constructor private हो सकता है?

हां. Private constructor बाहर से object बनाना रोकता है — यही Singleton pattern और utility classes का core है.