I am studying for an exam and wanted to verify that I am understanding how to build a copy constructor that avoids privacy leaks. Specifically a copy constructor that takes in an Object such as Bill. In this example the Bill class has instance variables Money and Date that are type object:
private Money amount;
private Date dueDate;
and my constructor right now looks like this:
public Bill(Bill toCopy){
this.amount = new Money(toCopy.amount);
this.dueDate = new Date(toCopy.dueDate);
}
Do I need to make a setter/mutator method for dueDate and amount (such as setDueDate and setAmount), or can I do the above within my copy constructor? Also, we don't need to worry about privacy leaks with primitive types right? i.e If I had a constructor that only took in doubles
Thank you for any feedback!