user2712735
user2712735

Reputation:

Types of polymorphism. More than one?

I am still in college and only remember about hearing about 1 type of polymorphism when learning about Java; however, when I was in a C# class, I just remember my professor talking about 4 types of polymorphism.

I am only aware of subclassing and defining specific behavior within more specific classes, and being able to call those specific behaviors with a single method in the base class because of an interface signature.

What are the other types, and are they of as big of an importance as the only type we were taught above? Is that why there are not taught?

Upvotes: 2

Views: 164

Answers (1)

Christopher Rucinski
Christopher Rucinski

Reputation: 4867

Yes there are 4 kinds of polymorphism

  1. Overloading (Same function names, different parameter types. This includes operator overloading and is done at compile time)

  2. Parametric polymorphism (These are like templates in C++) Compile time

  3. Subtype polymorphism (if a function has a parameter with a subtype, for example Car->Honda, f(Car), then function f will accept f(Honda) as well.) Runtime

  4. Parameter coercion (This is an implicit type conversion. For example, a function might require a double/real/float, but will accept an int and will implicitly upcast the parameter) Compile time

Reference:

Upvotes: 5

Related Questions