I have two questions about the following code. 1. How to constructor the third constructor without using setter? 2. what does this() do in the last constructor.
public class Person {
private String name;
private String address;
Person(){}
Person(String name){
this.name = name;
}
Person(String address){
//Person(java.lang.String) is already defined.
}
Person(String name,String address){
this();
this.name = name;
this.address = address;
}
}
My solution for question is Person(Object address){ this.address = (String)address; } However, i am not sure about this.
and i think this(); in the last constructor calls constructor Person(){}, but if it does, is it mean that two Person objects are created when i call
Person p = new Person("myName","myAddress");
Thanks!!!