Thank you Mohamed & Eduardo! That really clears this up for me!
I reviewed the code in SortedMap as Mohamed suggested, it was very helpful.
To expand on this, consider
SortedMap sortedMap = new TreeMap();
TreeMap treeMap = new TreeMap();
Object obj = new TreeMap();
Can be described generically as
Implementation name = new ClassName();
1) sortedMap would contain all of the methods and variables of a SortedMap, but none of the TreeMap that were not implemented to satisfy the SortedMap interface.
2) treeMap would contain all of the methods and variables of a TreeMap, including those of a SortedMap because TreeMap must satisfy the implementation of a SortedMap.
3) obj would contain all of the methods and variables of an Object, but none of the TreeMap or SortedMap.
So I could do something like - the syntax may not be exactly correct.
public interface Shipment {
public
String getShippingInstructions();
}
public class Order implements Shippment{
public String getShippingInstructions() {
return "Ship by slow boat";
}
}
public class Gift implements Shipment {
public String getShippingInstructions() {
return "Ship by
rocket and attach thank you card";
}
}
Shipment shipment1 = new Order();
shipment1.getShippingInstructions() returns "Ship by slow boat"
Shipment shipment2 = new Gift();
shipment2.getShippingInstructions() returns "Ship by rocket and attach thank you card"
Object shipment3 = new Gift();
shipment3.getShippingInstructions() won't compile because shipment3 does not contain method getShippingInstructions().
So the seemingly different Gift and Order objects can both go through the same shipping process.
One use of
polymorphism.
Am I close? Way off?