Special welcome gift. Get 50% off your first courses with code “AS50”. Find out more!

HomeInterviewC++ Q/AWhat is the difference between compile time polymorphism and runtime polymorphism?
courses 9

What is the difference between compile time polymorphism and runtime polymorphism?

In C++, polymorphism refers to the ability of objects of different classes to respond to the same method call in different ways. There are two main types of polymorphism in C++: compile-time polymorphism and runtime polymorphism.

Compile-time polymorphism, also known as static polymorphism, is implemented through function overloading and operator overloading. Function overloading allows multiple functions with the same name but different parameter lists to be defined in the same scope.

Runtime polymorphism, also known as dynamic polymorphism, is implemented through inheritance and virtual functions. Inheritance allows classes to inherit properties and behaviors from their base classes. Virtual functions allow derived classes to override the implementation of a base class method so that objects of the derived class can respond to the same method call in different ways. The actual implementation of a virtual function is determined at runtime based on the actual type of the object, not just the declared type.

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

Categories

ads sidebar 1

You May Also Like

Oracle has several modes for shutting down the database: In normal mode, the database is shut down by default. It...
Materialized views are items that contain condensed sets of data from base tables that have been summarized, clustered, or aggregated. They...
Every database in Oracle has a tablespace called SYSTEM, which is generated automatically when the database is created. It also...