public class Person
{
private String name;
private String streetAddress;
private String cityStateZip;
public Person()
{
name = "John Doe";
streetAddress = "55 Main Street";
cityStateZip = "Anywhere, MA 00001";
}
public Person(String n, String s, String c)
{
name = n;
streetAddress = s;
cityStateZip = c;
}
public String getName()
{
return this.name;
}
public void setName()
{
this.name = name;
}
public String getStreetAddress()
{
return this.streetAddress;
}
public void setStreetAddress()
{
this.streetAddress = streetAddress;
}
public String getCityStateZip()
{
return this.cityStateZip;
}
public void setCityStateZip()
{
this.cityStateZip = cityStateZip;
}
public String toString()
{
String str = name + "\n" + streetAddress + "\n" + cityStateZip + "\n";
return str;
}
}
In the code above I have written a class that will create a person object and will be used to create other classes that will implement this person class. While I was writing this superclass I thought, what is the difference between setter methods and constructors? Are setter methods simply helpful because you can easily just do .set(methodName) or? Would someone be willing to explain the difference between my constructor and my setter method?