How to Use Parameterized Constructor in Java


In this example, we may see how to use parameterized Constructor in Java.

Source Code

package com.beginner.examples;

public class ParameterizedConstructorExample {

	public ParameterizedConstructorExample(String str){
		 System.out.println("Constructor with String object: " + str);
    }
     
    public static void main(String a[]){
    	ParameterizedConstructorExample p = new ParameterizedConstructorExample("java");
    }
}

Output:

Constructor with String object: java
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments