Knowee
Questions
Features
Study Tools

Which of the following is an example of runtime polymorphism?Function overloadingOperator overloadingVirtual functionsInline functions

Question

Which of the following is an example of runtime polymorphism?

  • Function overloading
  • Operator overloading
  • Virtual functions
  • Inline functions
🧐 Not the exact question you are looking for?Go ask a question

Solution

Virtual functions are an example of runtime polymorphism.

Here's why:

Polymorphism in object-oriented programming allows objects of different classes to be treated as objects of a common superclass. There are two types of polymorphism: compile-time polymorphism (or static binding) and runtime polymorphism (or dynamic binding).

  1. Function overloading and operator overloading are examples of compile-time polymorphism. In these cases, the function to be invoked is determined at compile time based on the types and number of arguments.

  2. Virtual functions, on the other hand, are used to achieve runtime polymorphism. They are declared (and possibly defined) in a base class, and can be overridden in derived classes. The function to be invoked is determined at runtime based on the type of the object pointed to or referred to, not the type of pointer or reference. In other words, the virtual function call is resolved dynamically at runtime.

  3. Inline functions are not related to polymorphism. They are a performance optimization technique where the function's code gets inserted into the caller's code body instead of making a function call.

This problem has been solved

Similar Questions

Which of the following is an example of runtime polymorphism?Function overloadingOperator overloadingVirtual functionsInline functions

answerWhich of these allows compile-time polymorphism?OptionsMethod overloadingMethod overridingBothNone of the above

Select the correct answerIn Java, what concept allows us to implement runtime polymorphism?OptionsMethod overridingMethod overloadingConstructorsStatic methods

A form of polymorphism that generally occurs during compile time is called overloading.

In C++, polymorphism requires :Inheritance onlyVirtual functions only References onlyInheritance, Virtual functions and reference

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.