Java OOP SHORT ANSWER QUESTIONS INHERITANCE &
POLYMORPHISM 2 QUESTIONS 1-A
_____________ instance variable in the superclass is fully accessible in
subclasses. 2-A
_____________ instance variable in the superclass is not accessible in
subclasses or in any other class. 3-A
_____________ instance variable in the superclass in fully accessible in the
subclasses but not in other classes. 4-A method in
a subclass that shares the same name and parameter list as a method in the
superclass is said to be a(n) _______________ method. 5-We can
specify to Java that it needs to verify that a method is in fact overriding
another method by adding _______________ on the line above the method header. 6-From inside
a subclass with an overriding method named toString(), we can call the
superclass’ toString method by using ____________________________. 7-_________________
allows us to have a superclass reference to a subclass object. This allows us to process a superclass and
subclass objects at once in a loop. We
can also place all of these object in a single array. 8-True or
false. Polymorphism can be used with
inheritance and it can also be used with interfaces. 9-In the polymorphic
reference below, we know that ClassA is a _______________ of ClassB. ClassA a = new
ClassB(); 10-True or
False. Considering the above
polymorphic reference, we can call a.methodName() only if methodName() exists
in ClassA. 11-True or
False. In the above polymorphic
reference, if we call a.methodName() and methodName() exists in both ClassA
and ClassB, then the ClassB method will be executed. 12-In Java,
the ______________ class is always at the top of the class hierarchy. All classes inherit from this class. 13-The
following code has an error associated with the toString method in
Frost. What needs to be changed to fix
the error?
14-Let’s
consider the classes below. The Enemy
class has a damage method that calculates the standard damage made by an
enemy. The Ghost class overrides that
method so that Ghosts do twice the damage.
15-Let’s
consider the classes below. There is
an error in the Boss class. How do you
fix it? Hint: Removing the @Override would actually
make the error go away but that is not what we want to do here. We want to keep the @Override and fix the
error.
SOLUTIONS Click here. |
||||||||||||
|