Java Program using parameterized constructor
In this program, You will learn how to implement parameterized constructor in java.
Main(int a) {
//statement
}
Example: How to implement parameterized constructor in java.
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