J
Jerry
Can anyone help me to answer the following interview question? Thanks!
1. Change the following code so an instance of Person is immutable
once created. Please note that citiesVisited is an array
and may require special consideration.
public class Person {
/** Name of the Person */
String name;
/** Cities he/she has visited */
String[] citiesVisited;
public Person(String n, String[] cities) {
name = n;
citiesVisited = cities;
}
/**
* Accessor for citiesVisited
* @return Returns the citiesVisited.
*/
public String[] getCitiesVisited() {
return citiesVisited;
}
/**
* Accessor for name
* @return Returns the name.
*/
public String getName() {
return name;
}
}
1. Change the following code so an instance of Person is immutable
once created. Please note that citiesVisited is an array
and may require special consideration.
public class Person {
/** Name of the Person */
String name;
/** Cities he/she has visited */
String[] citiesVisited;
public Person(String n, String[] cities) {
name = n;
citiesVisited = cities;
}
/**
* Accessor for citiesVisited
* @return Returns the citiesVisited.
*/
public String[] getCitiesVisited() {
return citiesVisited;
}
/**
* Accessor for name
* @return Returns the name.
*/
public String getName() {
return name;
}
}