public class MyDefaultConstructor {
public MyDefaultConstructor(){
System.out.println("I am inside default constructor...");
}
public static void main(String a[]){
MyDefaultConstructor mdc = new MyDefaultConstructor();
}
}
Output:
I am inside default constructor...
Write a Program for Parameterized Constructor in Java
public class MyParameterizedConstructor {
private String name;
public MyParameterizedConstructor(String str){
this.name = str;
System.out.println("I am inside parameterized constructor.");
System.out.println("The parameter value is: "+str);
}
public static void main(String a[]){
MyParameterizedConstructor mpc = new MyParameterizedConstructor("Madhu Raj");
}
}
Output:
I am inside parameterized constructor.
The parameter value is: Madhu Raj
No comments:
Post a Comment