- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
What is the difference between compile time polymorphism and runtime polymorphism in java?
If we perform (achieve) method overriding and method overloading using instance methods, it is run time (dynamic) polymorphism.
In dynamic polymorphism the binding between the method call an the method body happens at the time of execution and, this binding is known as dynamic binding or late binding.
Example
class SuperClass{ public static void sample(){ System.out.println("Method of the super class"); } } public class RuntimePolymorphism extends SuperClass { public static void sample(){ System.out.println("Method of the sub class"); } public static void main(String args[]){ SuperClass obj1 = new RuntimePolymorphism(); RuntimePolymorphism obj2 = new RuntimePolymorphism(); obj1.sample(); obj2.sample(); } }
Output
Method of the super class Method of the sub class
If we perform (achieve) method overriding and method overloading using static, private, final methods, it is compile time (static) polymorphism.
In static polymorphism the binding between the method call an the method body happens at the time of compilation and, this binding is known as static binding or early binding.
Example
class SuperClass{ public static void sample(){ System.out.println("Method of the super class"); } } public class SubClass extends SuperClas { public static void sample(){ System.out.println("Method of the sub class"); } public static void main(String args[]){ SuperClass.sample(); SubClass.sample(); } }
Output
Method of the super class Method of the sub class
- Related Articles
- Difference between compile-time polymorphism and runtime polymorphism
- What is compile time polymorphism in C#?
- Runtime Polymorphism in Java
- Java Runtime Polymorphism with multilevel inheritance
- What is the difference between static and dynamic polymorphism?
- What is runtime polymorphism or dynamic method overloading?
- Dynamic method dispatch or Runtime polymorphism in Java
- Virtual Functions and Runtime Polymorphism in C++
- Difference Between Inheritance and Polymorphism
- Using run-time polymorphism in Java
- What is run time polymorphism in C#?
- Difference between Compile Time Errors and Runtime Errors in C Program
- Polymorphism in Java
- What is overriding and overloading under polymorphism in java?
- What is the difference between compile time errors and run time errors in Java?

Advertisements