polymorphism Flashcards
What is the main idea behind polymorphism in programming?
A) To use multiple inheritance to create complex hierarchies
B) To allow methods or variables to appear in multiple forms
C) To enable only static methods in classes
D) To limit the number of classes in a program
Correct Answer: B
How does polymorphism enhance object-oriented programming?
A) By enforcing strict data types
B) By limiting extensibility
C) By allowing a single interface to be used by different classes
D) By requiring only one form of method in all classes
Correct Answer: C
Polymorphism works well with which of the following principles?
A) Encapsulation and information hiding
B) Static variables and constants
C) Method chaining
D) Data duplication
Correct Answer: A
Which type of polymorphism is also known as early binding?
A) Static polymorphism
B) Dynamic polymorphism
C) Runtime polymorphism
D) Late binding
Correct Answer: A
What is an example of static or compile-time polymorphism?
A) Method overriding
B) Abstract methods
C) Method overloading
D) Dynamic binding
Correct Answer: C
How does method overloading work?
A) Methods have the same name but different return types only
B) Methods have the same name but different parameters
C) Methods have different names and parameters
D) Only one method can be defined per class
Correct Answer: B
Which of the following is an example of dynamic polymorphism?
A) Method overloading
B) Constructor overloading
C) Method overriding
D) Static method creation
Correct Answer: C
What is required for method overriding to work?
A) Methods must have the same name and signature
B) Methods must have different return types
C) Methods must belong to the same class
D) Methods must not be inherited
Correct Answer: A
Why is dynamic polymorphism also called late binding?
A) The binding happens at compile-time
B) The compiler binds the method at runtime
C) All method names are determined before execution
D) It allows only one form of a method per class
Correct Answer: B
Which of the following is true about polymorphic variables?
A) They are always primitive types
B) They can refer to objects of different types within the same inheritance hierarchy
C) They must have private access
D) They are used only in static polymorphism
Correct Answer: B
Which of these statements about polymorphic variables is NOT valid?
A) Employee employee = new PartTime();
B) Employee employee = new FullTime();
C) Employee employee = new Person();
D) Employee employee = new Manager();
Correct Answer: C
Which statement best describes dynamic binding?
A) The method call is attached to the method at compile time
B) The method call is attached to the method at runtime
C) All methods are predefined at compile-time
D) No inheritance is used in dynamic binding
Correct Answer: B
In the statement Employee employee = new PartTime();, what kind of relationship does this indicate?
A) An unrelated class relationship
B) A polymorphic relationship
C) A private inheritance relationship
D) A method override relationship
Correct Answer: B
What does it mean if a method is “redefined” in a subclass?
A) The method must be private
B) The method cannot be inherited
C) The method has a similar algorithm but different implementation in the subclass
D) The method signature changes completely
Correct Answer: C