as you can see the class below declares 2 private instance variables and 2 get & 2 set methods associated with each private member to allow for manipulation and validation of them.
My question is: which is better to use in the constructor deceleration, the instance variables directly as shown in the snippet below or to use the set methods associated with them and also which is promote good software practices to use in the toString method, the instance variables or their getter methods?
thank you for your time.
public Class Employee { private String firstName; private String lastName; public Employee (String first, String last) { firstName = first; lastName = last; }//end of constructor public void setFirstName(String first) { firstName = first; }//end of method setFirstName public String getFirstName() { return firstName; } public void setLastName(String last) { lastName = last; }//end of method setLastName public String getLastName() { return lastName; }//end of method getLastName public String toString() { return String.format ("%s: %s %s\n", "Employee Name: ", firstName, lastName); }//end of method toString }//end of class Employee