Question: Create another version of the Person class called PersonSafer. This class should not be subclassable, and should not allow any changes to the attribute data

Create another version of the Person class called PersonSafer. This class should not be subclassable, and should not allow any changes to the attribute data once they have been set, i.e. it should be immutable. Try the same process as before but using the PersonSafer class instead of Person/EvilPerson and ensure that it cannot be misused as the Person class can be.

Person Class:

public class Person { String name; String phone;

public Person() { name = new String(); phone = new String(); }

public Person(String name, String phone) { this.name = name; this.phone = phone; }

public void setName(String name) { this.name = name; }

public void setPhone(String phone) { this.phone = phone; }

public String getName() { return name; }

public String getPhone() { return phone; }

}

Evil Person Class:

public class EvilPerson extends Person { public EvilPerson(String name, String phone) { super(name,"n/a"); } public void setPhone(String phone) { this.phone = "n/a"; }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!