Question: I need to create file called EvilPerson.java. This implements a class that inherits from Person. The EvilPerson class doesnt want you to be able to

I need to create file called EvilPerson.java. This implements a class that inherits from Person. The EvilPerson class doesnt want you to be able to set a phone number for a user, so it always stores the text n/a in the phone attribute. You should define a constructor for EvilPerson that takes in a name and a phone number, stores the name correctly but throws away the phone number values and stores n/a there instead. The setPhone() method from Person should also be overridden in EvilPerson to do the same thing (store n/a instead of the provided phone number). In the UsePerson.java file instantiate an EvilPerson object after you instantiate the Person object. Try and give a reasonable name and phone number for EvilPerson. Add another call to showPerson() and give the EvilPerson object as the argument to that call. You should see n/a output for the EvilPersons phone number.

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; }

}

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!