Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step: 3

blur-text-image

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

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

Students also viewed these Databases questions