I'm hanging tough, please help.
This is a example from
Java 2 Cert. study guide Roberts and Heller page 52
The hierarchy exists - Person is the base class and Parent is a sub.
public class Classroom {
private Hashtable inTheRoom = new Hashtable(); //creates hastable object
public void enterRoom(Person p) {
inTheRoom.put(p.getName(), p);
// hashtable item is added with (p.getName()) as the key and p the object.
// getName is not in the API? what does this do?
}
public Person getParent(
String name) {
Object p = inTheRoom.get(name);
// p holds key/value "name" of type Object from the hashtable inTheRoom
if (p instanceof Parent) {
return (Parent)p;
}
else {
return null;
}
}
}
Looking at the API and this example:
Hashtable myhashtable = new Hashtable();
myhashtable.put("one", new Integer(1));
myhashtable.put("two", new Integer(2));
myhashtable.put("three", new Integer(3));
Where the number names are the keys.
The objects are wrapper Integer objects representing the values(1,2,3).
Now looking at the code snipplet:
inTheRoom.put(p.getName(),p);
//the hashTable is "inTheRoom"
//"put" is putting the "p.getName()" key and object p passed in(Person)p)).
Am I getting this stuff right?