Alex Rivera | Logout

Explain polymorphism

Asked 2010-07-23T21:00:35.510
16

What is polymorphism? I'm not sure I am understanding it correctly.

In the Python scope, what I am getting out of it is that I can define parameters as followed:

def blah (x, y)

without having to specify the type, as opposed to another language like Java, where it'd look more along the lines of:

public void blah (int x, string y)

Am I getting that right?

Edit
Report

2 Answers

1

Short answer: The ability to treat programmatic type instances of different types as the same for certain purposes.

Long answer: From Ancient Greek poly (many) + morph (form) + -ism.

Polymorphism is a general technique enabling different types to be treated uniformly in some way. Examples in the programming world include:

  • parametric polymorphism (seen as generics in Java)
  • subtyping polymorphism, implemented in Java using dynamic message dispatch between object instances.
  • ad-hoc polymorphism, which relates to the ability to define functions of the same name that vary only by the types they deal with (overloading in Java).

The word polymorphism is also used to describe concepts in other, unrelated, domains such as genetics.

answered 2010-07-23T21:22:55.573
-3

The ability to define a function in multiple forms is called Polymorphism. In C#, Java, C++ there are two types of polymorphism: compile time polymorphism (overloading) and runtime polymorphism (overriding).

Overriding: Overriding occurs when a class method has the same name and signature as a method in parent class.

Overloading: Overloading is determined at the compile time. It occurs when several methods have same names with:

  1. Different method signature and different number or type of parameters.
  2. Same method signature but different number of parameters.
  3. Same method signature and same number of parameters but of different type
answered 2010-07-23T21:10:04.010

Your Answer