I have two classes, one is House, which surely has other attributes, but I have included only the one with which I have had problem:
public class House {
private Address addressOfHouse;
public House (Address addressOfHouse){
this.setAddressOfHouse(addressOfHouse);
public Address getAddressOfHouse() {
return addressOfHouse;
}
public void setAddressOfHouse(Address addressOfHouse) {
this.addressOfHouse = addressOfHouse;
}
}
The other is Address:
public class Address {
public String streetName;
public String city;
public int postalCode;
public Address (String streetName, String city, int postalCode){
this.streetName=streetName;
this.city=city;
this.postalCode=postalCode;
}
public String getStreetName() {
return streetName;
}
public String getCity() {
return city;
}
public int getPostalCode() {
return postalCode;
}
}
When I create an object "house", set an address to it and try to call the method "getAddressofHouse":
public class Main {
public static void main(String[] args) {
Address address2 = new Address("Y", "Praha", 11000);
House house2 = new House (address2);
System.out.println(house2.getAddressOfHouse());
It does not give me the address of the house. It gives me this:
com.company.Address@7f63425a
My problem is to know what I have done wrongly with my setter and getter of the address in the class "House". It is an exercise that I have been doing, and it asks me to have an attribute called "addressOfHouse" with with data type "Address" (the class "Address"). So I suppose that I have to call the address of the house through the method "getAddressOfHouse", but I have been trying it and it has not worked at all. Could you help me with it? If you think that I should put the whole code here, I will do it. I thank you all in advance.