<- People Behind Informatics


All 0-9 A B C D E F G H I J K L M N O P Q R S T U V W XY Z




 
Polymorphism
We call variables that can take on various forms (that is, that can have different types) polymorphous. Procedures with polymorphous parameters are called polymorphous procedures. Because an object of a subclass is also an object of its superclass, wherever an object of the superclass can be used, we can use an object of a subclass instead – but not inversely! Thus we can assign to any variable or parameter of a given type a value of any subtype of this type. This makes the object variables or parameters polymorphous. An object variable can change its type at run time. We can assign a Truck instance to a Vehicle variable. Note that it is not the object instance that changes its type, but the variable that can contain references to various object instances. We call the actual type the dynamic type and the declared type the static type. Assignment is not permitted between objects if the dynamic type of the right-hand expression is neither a subtype nor a supertype of the declared type of the left-hand expression. To this extent polymorphism is restricted: Vehicle variables cannot be assigned to Person objects. Simply stated, assignments are possible only along the type hierarchy that begins at the declared type. Methods are polymorphous procedures: they can be applied to any object of a class hierarchy. Polymorphism in object-oriented languages is restricted to types within a class hierarchy. . Class Car serves as abstract superclass [Source:Laszlo Böszörmenyi, Carsten Weich; Programming in Modula-3; 1996]
 

 

<- People Behind Informatics


Home  |  Top  |  Search  |  Gallery  | Glossary  | Sitemap  |  Making Of  |  Help