WorksheetsPolymorphism - Objective Exercises
Total questions: 11
Worksheet time: 9mins
Name
Class
Date
1.
Which of the following statements is an advantage of polymorphism?
a)
The same program logic can be used with objects of several related classes.
b)
Variables can be re-used in order to save memory.
c)
Constructing new objects from old objects of a similar class saves time.
d)
Polymorphism is a dangerous aspect of inheritance and should be avoided.
2.
The following key words are normally found in the inheritance and polymorphism concepts EXCEPT
a)
instanceof
b)
abstract
c)
extends
d)
private
3.
Why is the class member, studentName declared private? (Choose the best answer.)
a)
So that no classes outside of Student can interfere and use the studentName attribute
b)
Because all class members are required to be declared private.
c)
Because it facilitates record keeping.
d)
Because the programmer wishes to protect the program against hackers wanting to steal vital information.
4.
Which of the following statements is TRUE?
a)
Polymorphism and inheritance is essentially the same thing.
b)
Polymorphism means that the method executed in response to a given message will vary according to the class to which the object belongs.
c)
The instance of operator tests whether an object exist.
d)
Polymorphism uses array of subclasses.
5.
What is the purpose of defining multiple constructors?
a)
Multiple constructors are easier to write than a single constructor.
b)
The Java constructors are easier to write than a single constructor.
c)
Multiple constructors give the client more flexibility in creating instances.
d)
Programs with multiple constructors are easier to read than a single constructor.
6.
What is the output of running the class c?
a)
AB
b)
BA
c)
AA
d)
BB
7.
Which of the following statements about the reference super written in a child class is TRUE?
a)
It must be used every time method from the superclass is called.
b)
It must be the last statement of the constructor.
c)
It must be the first statement of the constructor.
d)
It can only be used once in a program.
8.
Which of the following statement is TRUE?
a)
Objects cannot be instantiated from concrete class and abstract class.
b)
Abstract and concrete classes can have or inherited any abstract methods from the superclass.
c)
Concrete class can have concrete methods and abstract methods which will be defined in the subclass.
d)
If the subclass does not override the abstract methods from the superclass, the subclass must be declared as abstract.
9.
What will happen if a class is declared as an abstract class?
a)
All the derived classes must be declared as abstract class
b)
All the derived classes must implement the undefined method in the abstract class
c)
Derived classes cannot redefine the abstract method
d)
The abstract class can create its own object
10.
Which of the following scenario shows the advantage of polymorphism?
a)
A function can be given a meaningful name without having to change it to accommodate to rules against having multiple methods of the same name in a single function.
b)
The extension of a class makes the member variables of the parent available to the class, and saves the time of having to redefine these member variables.
c)
The introduction of a new class to an already functioning framework of classes using inheritance only requires a user to implement the new class by extending a parent class and adding the appropriate method.
d)
The extension of a class does not require the programmer to write a method that is defined in the parent. The class instead can call the parent method whenever it wants to.
11.
Which of the following statements are CORRECT?
a)
A public field or method is accessible to any class of any parentage in any package.
b)
A package field or method is accessible to the subclasses
c)
A protected field or method is accessible to the class itself, its subclasses, and classes in the same package.
d)
A private field or method is accessible only to the class in which it is defined.
100 %
