java copy constructor code example
Example: copy constructor in java
public class CopyConstructorExample {
private int someInt;
private String someString;
private Date someDate;
public CopyConstructorExample(CopyConstructorExample example) {
this.someInt = example.getSomeInt();
this.someString = example.getSomeString();
this.someDate = new Date(example.getSomeDate().getTime());
}
}
public class UsageExample {
public static void main(String[] args) {
CopyConstructorExample example = new CopyConstructorExample(5, "Test");
CopyConstructorExample copy = new CopyConstructorExample(example);
}
}