1. Write a piece of code, but why can"t you output the content?
2.import java.util.HashMap;
public class House {
private String name;
private HashMap < String,House > has=new HashMap < String,House > ();
public House (String name) {
this.name=name;
}
public void setExit (String dir,House house) {
has.put(dir,house);
}
public String getExitDes () {
StringBuffer buffer=new StringBuffer();
for(String s:has.keySet()){
buffer.append(s);
buffer.append(has.get(s));
}
return buffer.toString();
}
public static void main (String [] args) {
House house=new House("");
House house1=new House("");
House house2=new House("");
house.setExit("left", house1);
house.setExit("right", house2);
System.out.print(house.getExitDes());
}
}
3. After running, the output:
leftTest.House@2a139a55rightTest.House@15db9742 does not output room information.