ln014 - Polymorphism A closer look at types. polymorphism...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Polymorphism Chap 8 polymorphism comes from Greek meaning ‘many forms’ In programming: Def : A function or operator is polymorphic if it has at least two possible types. A closer look at types. ...
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Polymorphism i) Overloading Def: An overloaded function name or operator is one that has at least two definitions, all of different types. Example : In Java the ‘+’ operator is overloaded. String s = “abc” + “def”; int i = 3 + 5; +: String * String String +: int * int int
Background image of page 2
Polymorphism Example : Java allows user defined polymorphism with overloaded function names. bool f (char a, char b) { return a == b; } bool f (int a, int b) { return a == b; } f : char * char bool f : int * int bool Note: ML does not allow function overloading
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Polymorphism ii) Parameter Coercion Def : An implicit type conversion is called a coercion . Coercions usually exploit the type-subtype relationship because a widening type conversion from subtype to supertype is always deemed safe
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/03/2011 for the course CSC 301 taught by Professor Hamel during the Spring '08 term at Rhode Island.

Page1 / 8

ln014 - Polymorphism A closer look at types. polymorphism...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online