Java Program using parameterized constructor


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


Main(int a) { }


Example: How to implement parameterized constructor in Java

Run it Now
class Main {

    int x;

    Main(int a) {
        x = a;
        System.out.println("Parameterized 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(10);
        t.display();
    }
}

Output:

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