answersLogoWhite

0

The simple answer is that compile-time polymorphism occurs at compile time while runtime polymorphism occurs at runtime.

The actual answer is that compile-time polymorphism results in the compiler generating source code on your behalf while runtime polymorphism relies on function pointers or virtual methods to determine the next instruction at runtime.

Compile-time polymorphism therefore applies to template functions and classes since that is the only way the compiler can generate source code on your behalf. To achieve this, the runtime type for the template parameters must be fully-defined at compile time, even if those types have runtime polymorphic characteristics of their own.

Runtime polymorphism applies to virtual methods and function pointers, both of which can be used to dynamically alter the execution path of your program. Virtual methods are made possible through virtual tables, which are essentially just arrays of function pointers. Each runtime type that derives from a base class with virtual methods provides its own virtual table, thus the runtime type determines which specific function overrides will be invoked at runtime, even if the runtime type cannot be determined at compile time. In this way you can generalise your code to work with the base type but still get the expected polymorphic behaviour whenever a derived type is passed instead.

User Avatar

Wiki User

10y ago

What else can I help you with?

Continue Learning about Engineering

What is Difference between dynamic polymorphism and static polymorphism with example?

Static polymorphism is used the concept of early binding or we can say compile time binding where as dynamic polymorphism used the concept of late binding or run time binding.


What is difference between static remote method invocation and dynamic remote method invocation?

Typical way for writing code that uses RMI is similar to the process for writing RPC ❍ declare the interface in IDL, compile the IDL file to generate client and server stubs, link them with client and server side code to generate the client and the server executables ❍ referred to as static invocation ❍ requires the object interface to be known when the client is being developed ❒ Dynamic invocation ❍ the method invocation is composed at run-time invoke(object, method, input_parameters, output_parameters) ❍ useful for applications where object interfaces are discovered at run-time, e.g. object browser, batch processing systems for object invocations, "agents"


What is compile time polymorphism in java?

Compile Time Polymorphism in Java is when you have the several methods with same name and different parameters and compiler has to decide how to select which method has to run based on the arguments hence the name Compile time polymorphism or method overloading.


Why does C plus plus allows static binding and not dynamic binding?

Dynamic binding, or late binding, is when the object code for the class does not get loaded into memory until it is needed. This saves time at module load time, at the cost of delayed execution for the first invocation.


Is run time initialization of an array an initialization or an assignment?

It is an initialisation. You cannot assign values to a dynamic array until it has been initialised. Static arrays can be initialised at compile time. They can also be assigned at compile time. void main() { // Compile time: // ========= // Initialise a static array. int arr1[10]; // Initialise and assign a static array. int arr2[10] = {0,1,2,3,4,5,6,7,8,9}; // Runtime: // ====== // Dynamic array (size unknown, no memory allocated) int* pArr[]; // Initialise (size known, allocate memory, 40 bytes): pArr = ( int* ) malloc( 10 * sizeof( int )); // Assign (set values of elements): int x; for(x=0;x<10;++x) pArr[x] = x; // Uninitialise (release memory). free( pArr ); return( 0 ); }

Related Questions

What is Difference between dynamic polymorphism and static polymorphism with example?

Static polymorphism is used the concept of early binding or we can say compile time binding where as dynamic polymorphism used the concept of late binding or run time binding.


Is late binding and dynamic binding related to polymorphism?

Late binding and dynamic binding are related to runtime polymorphism. By contrast, compile time polymorphism is known as static binding. Template functions and classes are examples of static binding because the exact type can be determined at compile time.


Define compile time polymorphism with short examples?

compiler can decide which form of the object should be invoked during compile time.this type of polymorphism is know as compile time polymorphism


Static vs dynamic binding in c plus plus?

Static binding occurs at compile time. Dynamic binding occurs at runtime.


What are different static and dynamic features of oops?

static feature are aspects of a program that are fixed at compile time dynamic feature can change at run time the static and dynamic is manifested in oo language in number of diff ways.we consider 1.static and dynamic typing 2." " " classes 3." " " method binding


What is difference between static remote method invocation and dynamic remote method invocation?

Typical way for writing code that uses RMI is similar to the process for writing RPC ❍ declare the interface in IDL, compile the IDL file to generate client and server stubs, link them with client and server side code to generate the client and the server executables ❍ referred to as static invocation ❍ requires the object interface to be known when the client is being developed ❒ Dynamic invocation ❍ the method invocation is composed at run-time invoke(object, method, input_parameters, output_parameters) ❍ useful for applications where object interfaces are discovered at run-time, e.g. object browser, batch processing systems for object invocations, "agents"


What is the difference between static memory versus dynamic memory?

Dynamic memory can be declared at run-time using the new and delete operators (or malloc and free in C), while static memory must be declared at compile-time.


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

Runtime prolymorphism means overriding compiletile polymorphism means overloading


At what time the memory is allocated for variable in c and c?

Static memory allocation occurs at compile time where as dynamic memory allocation occurs at run time.


What is compile time polymorphism in java?

Compile Time Polymorphism in Java is when you have the several methods with same name and different parameters and compiler has to decide how to select which method has to run based on the arguments hence the name Compile time polymorphism or method overloading.


Difference between dynamic and static memory?

dynamic is the study of motin,while static is at rest it means that the memory which is used at motin time as by usic calloc,mallaoc,free function ,on the other hand static is the memory which only used at compile time or at the time of work in during progrmming,static memory has drawback ,the drawback is that in this memory ware unable to use the excess memory as we allocate already to cover or improvre this type of problem we use dynamic memory allocation.


What is dynamic dispatching?

Dynamic dispatching, also known as late binding, is a technique used in object-oriented programming where the method to be called is determined at runtime based on the actual type of the object, rather than at compile time. This allows for flexibility in the behavior of objects and enables polymorphism.