सीधे मुख्य सामग्री पर जाएं

#44 What is Copy Constructor in Java ? Copy Constructor क्या है ? How to create Copy Constructor

package com.sudhirtheindian2.java123;

import java.lang.constant.Constable;

public class CopyConstructor {
int a;
String name;
CopyConstructor(){
a=40;
name="indian";
System.out.println(a+" "+name);

}

CopyConstructor(CopyConstructor reference){
a= reference.a;
name=reference.name;
System.out.println(a+" "+name);



}


public static void main(String[] args) {
CopyConstructor c = new CopyConstructor();
CopyConstructor c2 = new CopyConstructor(c);

// What is copy constructor in java ?

// whenever we pass object reference to the constructor
// then it is called copy constructor

}
}

टिप्पणियाँ

इस ब्लॉग से लोकप्रिय पोस्ट