- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference between compile-time polymorphism and runtime polymorphism
Polymorphism is one of the most important OOPs concepts. Its is a concept by which we can perform single task in multiple ways. There are two types of polymorphism one is Compile-time polymorphism and another is run-time polymorphism.
Method overloading is the example of compile time polymorphism and method overriding is the example of run-time polymorphism.
Sr. No. | Key | Compile-time polymorphism | Runtime polymorphism |
---|---|---|---|
1 | Basic | Compile time polymorphism means binding is occuring at compile time | R un time polymorphism where at run time we came to know which method is going to invoke |
2 | Static/Dynamic Binding | It can be achieved through static binding | It can be achieved through dynamic binding |
4. | Inheritance | Inheritance is not involved | Inheritance is involved |
5 | Example | Method overloading is an example of compile time polymorphism | Method overriding is an example of runtime polymorphism |
Example of Compile-time Polymorphism
public class Main { public static void main(String args[]) { CompileTimePloymorphismExample obj = new CompileTimePloymorphismExample(); obj.display(); obj.display("Polymorphism"); } } class CompileTimePloymorphismExample { void display() { System.out.println("In Display without parameter"); } void display(String value) { System.out.println("In Display with parameter" + value); } }
Example of Runtime Polymorphism
public class Main { public static void main(String args[]) { RunTimePolymorphismParentClassExample obj = new RunTimePolymorphismSubClassExample(); obj.display(); } } class RunTimePolymorphismParentClassExample { public void display() { System.out.println("Overridden Method"); } } public class RunTimePolymorphismSubClassExample extends RunTimePolymorphismParentExample { public void display() { System.out.println("Overriding Method"); } }
- Related Articles
- What is the difference between compile time polymorphism and runtime polymorphism in java?
- What is compile time polymorphism in C#?
- Runtime Polymorphism in Java
- Difference Between Inheritance and Polymorphism
- Virtual Functions and Runtime Polymorphism in C++
- Java Runtime Polymorphism with multilevel inheritance
- Difference between Compile Time Errors and Runtime Errors in C Program
- Dynamic method dispatch or Runtime polymorphism in Java
- What is runtime polymorphism or dynamic method overloading?
- What is the difference between static and dynamic polymorphism?
- Using run-time polymorphism in Java
- What is run time polymorphism in C#?
- Polymorphism in Java
- Polymorphism in Python
- Explain Polymorphism in PHP.

Advertisements