What does the makeDeepCopy Method mean? Also is it a constructor? and why is the data type the same as the class name. I assumed any method with the same name as the class would be a constructor?
public class Name {
// private instance => visible in Name class only!
private String firstName;
private String lastName;
// constructor
public Name(String firstName, String lastName) {
// this keyWord differentiates instance variable from local variable
// refers to the current object
this.firstName = firstName;
this.lastName = lastName;
}
public Name(Name name) {
// Copy constructor
this.firstName = name.getFirstName();
this.lastName = name.getLastName();
}
public static Name makeDeepCopy(Name name) {
// copy method
return new Name(name);
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String toString() {
return this.firstName + " " + this.lastName;
}
}