Summary of Class Presentation for June 23, 1999 Topics: Upcasting and Polymorphism Upcasting and polymorphism are the two foundations of object orientation. They are subtle and often work together, but they are very, very important. You should make certain you understand both and keep this understanding in your working memory. Upcasting means an object of a derived class can serve as if it were an object of it's base class. In particular, an object of the derived class can be assigned to an object variable of the base class, and an object of the derived class can be passed as a parameter or returned from a method when an object of the base class is specified. Finally, an item of a derived class can be placed in a container ( the only container we have covered thus far is the array. We will cover many other containers (called collections) on July 1st. ) that specifies objects of the base class. Since all classes in Java automatically inherit directly ( if they have no explicit base class) or indirectly ( if they have an explicit base class) from the Object class, a Java container or parameter or return value or object variable can be specified as of the Object class and an object of any class can be used. Polymorphism comes in many forms. The form we care about here is called object-oriented polymorphism. Object-oriented polymorphism means when an object of a derived class is serving as an object of a base class, calling a method of the base class through that object automatically calls the corresponding method of the derived class to which that object actually belongs. This is often called late binding of methods. Unlike in C++, the method in the derived class must have the same name and the same parameter types in the same order as the method in the base class for this overriding to occur. If the method in the derived class has the same name, but not the same parameter types, the name is overloaded, but the method used is determined by the types of the parameters actually passed on the call. Upcasting and polymorphism generally are used together. Several classes are derived from a common base class. Then objects of the various derived classes are used as if they were objects of the base class. This is upcasting. Methods of the base class are called through base class object variables that actually reference objects of the derived classes. Polymorphism ensures that the appropriate methods in the derived classes are actually called. The combination of upcasting and object-oriented polymorphism supports incremental development by allowing a programmer to insert a new derived class into an application without disturbing any of the application's already present code. The new derived class's objects automatically are used by the existing code just like objects of earlier derived classes from the same base class. This combination also makes use of commercial libraries for which source code is not provided to customers possible. This combination also makes component based development (CBD) possible.