Java Program using the default constructor


In this program, You will learn how to implement the default constructor in java.


Main(){ 
    //statemnet
}

Example: How to implement default constructor in java.

class Main {
    int x;
    Main() {
        x = 10;
        System.out.println("Default Constructor is called here");
    }

    void display() {
        System.out.println("The Value of x is:" + x);
    }

    public static void main(String args[]) {
        Main t = new Main();
        t.display();
    }
}

Output:

Default Constructor is called here
The Value of x is:10