answersLogoWhite

0


Best Answer

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

9y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

Runtime prolymorphism means overriding compiletile polymorphism means overloading

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why run time polymorphism is dynamic and compile time polymorphism is static?
Write your answer...
Submit
Still have questions?
magnify glass
imp
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.


What is dynamic method dispatch in java?

dynamic method dispatch is a technique by which a call to a overridden method is solved at runtime rather than compile time..this is how java implements runtime polymorphism.


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.

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.


Static vs dynamic binding in c plus plus?

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


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


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.


What is dynamic method dispatch in java?

dynamic method dispatch is a technique by which a call to a overridden method is solved at runtime rather than compile time..this is how java implements runtime polymorphism.


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.