polymorphism Flashcards

1
Q

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

A

Correct Answer: B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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

A

Correct Answer: C

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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

A

Correct Answer: A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which type of polymorphism is also known as early binding?

A) Static polymorphism
B) Dynamic polymorphism
C) Runtime polymorphism
D) Late binding

A

Correct Answer: A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is an example of static or compile-time polymorphism?

A) Method overriding
B) Abstract methods
C) Method overloading
D) Dynamic binding

A

Correct Answer: C

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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

A

Correct Answer: B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which of the following is an example of dynamic polymorphism?

A) Method overloading
B) Constructor overloading
C) Method overriding
D) Static method creation

A

Correct Answer: C

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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

A

Correct Answer: A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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

A

Correct Answer: B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

A

Correct Answer: B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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();

A

Correct Answer: C

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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

A

Correct Answer: B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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

A

Correct Answer: B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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

A

Correct Answer: C

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are accessors in the context of methods?

A) Methods that calculate object state
B) Methods that manage dynamic binding
C) Methods for accessing and modifying attributes
D) Methods that perform inheritance

A

Correct Answer: C

17
Q

What is the purpose of the getName() method in the context of accessors?

A) To modify the name attribute
B) To retrieve the name attribute
C) To delete the name attribute
D) To initialize the name attribute

A

Correct Answer: B

18
Q

What visibility modifier allows a method to be accessible by subclasses but not other classes?

A) Public
B) Private
C) Protected
D) Internal

A

Correct Answer: C

19
Q

What is an example of data hiding in object-oriented programming?

A) Declaring all methods as public
B) Making method parameters accessible by all classes
C) Defining attributes as private and using public methods to access them
D) Using static variables

A

Correct Answer: C

20
Q

How does a derived class use method overriding with a base class method?

A) By creating a method with a different signature
B) By providing a different implementation for a base-class method with the same signature
C) By making the base-class method private
D) By hiding the base-class method

A

Correct Answer: B

21
Q

Which access modifier allows methods to be visible only within the class in which they are defined?

A) Public
B) Private
C) Protected
D) Internal

A

Correct Answer: B

22
Q

Which is a key guideline for using polymorphism effectively?

A) Declare variables at the lowest possible class level
B) Always use dynamic polymorphism over static polymorphism
C) Use the highest level of abstraction possible
D) Avoid using access modifiers

A

Correct Answer: C

23
Q

What is the main benefit of using polymorphic methods in a program?

A) To create a single-use code
B) To make method overriding impossible
C) To enhance code reusability and flexibility
D) To simplify variable declaration

A

Correct Answer: C

24
Q

Which of the following is an example of a polymorphic message?

A) employee.getSalary()
B) employee = new Employee()
C) employee.salary = 5000
D) Employee employee = new Employee();

A

Correct Answer: A

25
Q

Why is it possible for Employee employee = new PartTime(); to work without errors?

A) Because Employee and PartTime are completely unrelated
B) Because PartTime is a derived class of Employee
C) Because Employee has private members
D) Because PartTime does not override any methods

A

Correct Answer: B

26
Q

What is the concept of late binding in polymorphism?

A) The method call is determined and attached at compile time
B) The method call is dynamically resolved at runtime
C) The method is hidden by the derived class
D) The method cannot be accessed by other classes

A

Correct Answer: B