Java Program using default constructor


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


Main(){ }


Example: How to implement default constructor in Java

Run it Now
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