Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Joe Celkos Data And Databases Concepts In Practice

Authors: Joe Celko

1st Edition

1558604324, 978-1558604322

More Books

Students also viewed these Databases questions