Week 9 Flashcards
A feature that allows us to perform an action in different ways
Polymorphism
Does polymorphism allow you to program in the general or the specific?
Polymorphism allows you to program in the general, rather than the specific
T/F - Polymorphism enables you to write programs that process objects that share the same superclass as if they were all objects of the superclass
True
A type defined by a subclass is called a _______, and a type defined by a superclass is called a _________
subtype, supertype
The key concept of polymorphism: “Relying on each object ‘knowing how…’ to do what?
Knowing how to do the right thing in response to the same method call
Why polymorphism powerful?
Makes the class flexible and extensible, simplifies programming by providing a single interface
Method overriding allows subclasses to do what?
Allow for the reuse of code
Subclasses can use all the general definitions the superclass provides and add specializations by overriding methods
What is the difference between polymorphism and inheritance?
Inheritance applies the behaviour of a superclass to a subclass.
Polymoprhism changes the behaviour of the superclass in the subclass.
These are useful for assigning common functionality to possibly unrelated classes:
Interfaces
2 unrelated classes implement the same interface, what happens with their methods and objects?
Classes that implement the same interface can have their objects respond to all of the interface method calls
T/F - There are more types of polymorphism than inheritance
False, there are 2 types of polymorphism, 5 types of inheritance
With polymorphism, we can design and implement systems that are _______ _________
easily extensible
T/F - Interaces are useful for assigning common functionality to possibly unrelated classes
True
T/F - Polymorphism enables you to deal in specifics
False, Polymorphism enables you to deal in generalities
T/F - Objects will behave in an appropriate manner even if you do not know their type, as long as they belong to the same inheritance hierarchy
True