Understanding Polymorphism
Understanding Polymorphism
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 1
(Answer all questions in this section)
1. Why would a programmer use polymorphism rather than sticking to a standard
array?
Mark for
Review
(1) Points
Because arrays only work using the same object type and polymorphism
provides a way around this. (*)
Because it is easier to add or remove objects using polymorphism even
when all of the objects are of the same type.
Because arrays are more complex and polymorphism simplifies them by
restricting them to only contain the same type objects.
A programmer wouldn't use polymorphism over a standard array.
Mark for
Mark for
Review
(1) Points
True (*)
False
Mark for
Review
(1) Points
Yes. Overriding is done within a single class and overloading is done through
a series of superclasses and their subclasses.
Yes. Overriding allows for the creation of an array of different object types
and overloading restricts an array to only contain the same object types.
Yes. Overriding is done in the subclass and allows for redefining a method
inherited from the superclass and overloading is done within a class and
allows for multiple methods with the same name. (*)
No, they are the same.
Mark for
Review
(1) Points
Abstract classes
Polymorphism
Inheritance
Dynamic Method Dispatch (*)
Mark for
Review
(1) Points
7. If we override the toString() method with the code below, what would be the
result of printing?
Mark for
Review
(1) Points
It would print the array one element at a time. The console screen would
display: 0 18 215 64 11 42
It would print the string returned from the method. The console screen would
display: [0,18,215,64,11,42,] (*)
It would print the array backwards. The console screen would display: 42 11
64 215 18 0
It would print the string returned from the method. The console screen would
display: {0, 18, 215, 64, 11, 42}
Mark for
Review
(1) Points
It restricts a class from being extendable and restricts methods from being
overridden. (*)
It permits access to the class variables and methods from anywhere.
It permits redefining methods of a parent class inside the child class, with
the same name, parameters, and return type.
It terminates the program.
There is no such keyword in Java.
Mark for
Review
(1) Points
10Identify the step (s) in creating a Triangle Applet that displays two triangles.
.
Mark for
Review
(1) Points