Polymorphism Flashcards
1
Q
What is POLYMORPHISM?
A
Polymorphism means many forms. It
means that two methods can have the same name but
different contents/functions.
Methods (behaviours) have the same name but
different parameter lists and processes
2
Q
What are the two types of polymorphism?
A
- Overloading (same class)
- Overriding (difference classes/inheritance)
3
Q
What are the ADVANTAGES of OVERLOADING?
A
- We don’t have to create and remember different names for functions doing the same thing.
- For example,, if overloading was not supported by Java, we would have to create method names like sum1, sum2,… or sum2Int, sum3Int, … etc. for every possible combination of parameters that might be used.
4
Q
What are the ADVANTAGES of OVERRIDING?
A
- Polymorphism is essential to object-oriented programming
for one reason: it allows a general class to specify methods
that will be common to all of its derivatives, while allowing
sub classes to define the specific implementation of some or
all of those methods. - Overridden methods are another way that Java implements
the “one interface, multiple methods” aspect of
polymorphism - Overridden methods allow us to call methods of any of the
derived classes without even knowing the type of derived
class object.