So I'm still a fledgling programmer and I would really appreciate it if someone could explain to me how exactly the code below functions.
I'm aware without some methods I didn't list here the code will not function but what baffles me starts at line eleven : String street is given the value of a variable that isn't indexed (to my knowledge) and yet I'm still able to return it with the value intended and not valueless s.
How is it exactly that String s and the other variables serving the same purpose don't modify the value of the variable I end up returning?
Once again I'm thankful for any help I get on this.
public class StreetAddress {
String street, city, state, zip;
StreetAddress(String s1, String c, String s2, String z) {
street = s1;
city = c;
state = s2;
zip = z;
}
void setStreet(String s) {
street = s;
}
String getStreet() {
return street;
}
void setCity(String c) {
city = c;
}
String getCity() {
return city;
}
void setState(String s) {
state = s;
}
String getState() {
return state;
}
void setZIP(String z) {
zip = z;
}
String getZIP() {
return zip;
}
String mailingLabel() {
return street + "\n" + city + ", " + state + " " + zip;
}
}
The class above would receive the information below and return a formatted label.
StreetAddress add = new StreetAddress("Cheese Island", "East Hemisphere", "The Moon", "99999999");
System.out.println(add.mailingLabel());
add.setStreet("Solar Flare");
add.setCity("Corona");
add.setState("The Sun");
add.setZIP("00000000");
System.out.println(add.mailingLabel());