
Education Journalist | Study Abroad Lead
Thе diffеrеncе bеtwееn Compile-time Polymorphism and Runtimе Polymorphism is that compilе-timе polymorphism, also known as mеthod ovеrloading, occurs whеn multiplе mеthods in a class havе thе samе namе but diffеrеnt paramеtеr lists whereas runtimе polymorphism, also known as mеthod ovеrriding, occurs whеn a subclass providеs a spеcific implеmеntation for a mеthod that is already dеfinеd in its supеrclass.
- Polymorphism is one of the most fundamental concepts used in Java.
- Polymorphism implies the fact that a single action/ task can be done through many different methods.
- In Java, a single message can be displayed in more than one form by using Polymorphism.
- Polymorphism is of two types- Compile time Polymorphism (also known as Static Polymorphism) and Runtime Polymorphism (also known as Dynamic Polymorphism).
| Table of Content |
Key Terms- Java, Polymorphism, Compile Time Polymorphism, Runtime Polymorphism
What is Polymorphism in Java?
[Click Here for Sample Questions]
The term Polymorphism means "many forms". In Java, this concept comes into play when there are many classes related to each other by Inheritance. As Inheritance allows us to use attributes and methods from other classes, Polymorphism uses those methods to perform different tasks.
For example, a superclass Animal
And it has a method called animalSound()
Subclasses of Animals could be Cats, Dogs, Lions, Birds - And they also have their own implementation of an animal sound (the dog barks, and the cat meows, etc.):
Now we can create Dog and cat objects and call the animalSound() method on both of them:

In this way Polymorphism helps to reuse attributes and methods of an existing class while creating a new class.
Also Read:
Compile Time Polymorphism vs Runtime Polymorphism
[Click Here for Sample Questions]
Polymorphism in Java is categorised into Command line Diversity and Runtime Polymorphism. This Command line diversity is Compile Time Polymorphism that works on method overloading.
- The call for given overloaded methods occurs at the time of compiling the attribute, thus this type of Polymorphism is also known as Static Polymorphism.
- Here, the parameters influence the type of overloaded method invoked.
- On the other hand, the call Resolution in Runtime Polymorphism occurs at the time of formation of objects rather than at the build time.
- Runtime Polymorphism applies the use of the method Overriding.
- The object directly decides the override method to be used at the time of compilation.
Compile Time Polymorphism
[Click Here for Sample Questions]
By definition Compile Time Polymorphism is the coupling of an object with its functionality at its Compile Time. This means that for an object, Java calls the most appropriate method at compile time by evaluating the method signatures.
The following points can help understand compile-time polymorphism more clearly:-
- It is achieved by Method overloading.
- Method overloading implies that one can have many different methods for the same name and same class but with a distinct prototype. In this way, a single command can be displayed in many ways.
- When function overloading is done at Compile time, Compile Time Polymorphism is made.
- It depends and varies with the type of technology used.
- It is also known as Static Polymorphism or Early Binding.
Compile Time Polymorphism Example
The example is illustrated below:

Compile Time Polymorphism Example
Runtime Polymorphism
[Click Here for Sample Questions]
Whenever an object exhibiting polymorphism becomes associated with its functionality at the run time (at the time of display), it is known as Runtime Polymorphism.
- The method to be invoked is evaluated and decided by the Java virtual machine at the Runtime.
- Method Overriding produces Runtime Polymorphism.
- Method Overriding states that the child class has the same method as its Parent class. This ultimately holds true for the implementation of the method by any of the Parent Classes of the concerned Child class.
- Runtime Polymorphism is also known as Dynamic Polymorphism or Late binding.
- The functional attribute involved can be modified as long as the Runtime has not started.
Runtime Polymorphism Example
Here is the example of runtime polymorphism:

Runtime Polymorphism Example
Difference between Compile-Time and Runtime Polymorphism
[Click Here for Sample Questions]
In the following table, the main differences between Compile time and Runtime Polymorphism are given:-
| Basis of difference | Compile Time Polymorphism | Runtime Polymorphism |
|---|---|---|
| Time of Binding | Compile Time Polymorphism states that Binding occurs at Compile time. | In Runtime Polymorphism Binding occurs Runtime and we can know which method is going to be invoked. |
| Inheritance involvement | Inheritance has no role to play here | Inheritance plays an integral role in this type of Polymorphism. |
| Type of Function used | Method overloading is used to produce compile-time polymorphism | Method Overriding is used to produce Runtime Polymorphism. |
| Utilities/Advantages | It helps to use many methods for the same name and same class but different signatures and return type. | It helps to use the same method for different names and classes related to each other by Inheritance. |
| Components used | It involves functions and operator overloading. | It operates via virtual functions and pointers. |
| Speed Of Execution | As the methods are invoked at the time of compilation, it takes negligible time for execution. | Since, the method is associated with the object at the runtime, Polymorphism gives comparatively slow execution. |
| Versatility | As everything is set up in the compile time, it is less versatile. | All the evaluation and execution happens in the Runtime, it is comparatively more versatile. |
Things to Remember
- In Java, Polymorphism is a way in which an object can be displayed in different forms.
- Polymorphism is of two types- Compile Polymorphism and Runtime Polymorphism.
- Compile time Polymorphism occurs when different methods for the same name and same class but differing signatures are used in Java.
- Runtime Polymorphism is used when the same methods are used for different names and classes related to each other by Inheritance.
- Method overloading produces Compile Time Polymorphism.
- Method Overriding is used to instil Runtime Polymorphism.
Read More:
Sample Questions
Ques. Which of the following is not true about polymorphism? (1 mark)
a) Helps in redefining the same functionality
b) Increases overhead of function definition always
c) It is feature of OOP
d) Ease in readability of program
Ans. Option b
Explanation: Polymorphism does not increase or decrease overhead of function definition. It just helps in redefining codes more efficiently
Ques. Which among the following can show polymorphism? (1 mark)
a) Overloading &&
b) Overloading <<
c) Overloading ||
d) Overloading +=
Ans. Option b
Explanation: Of all the options only insertion operator can be used for Polymorphism. Moreover, Polymorphism can only occur if any of these is applicable or being overloaded.
Ques. Which of the following is not a property of an object? (1 mark)
a) Properties
b) Names
c) Identity
d) Attributes
Ans. Option b
Explanation: Names are not the property of an object. An object can be identified in any name of object, address, etc. , but name solely cannot be the identity of that object.
Ques. Which of the following best describes member function overriding? (1 mark)
a) Member functions having the same name in derived class only
b) Member functions having the same name and different signature inside main function
c) Member functions having the same name in base and derived classes
d) Member functions having the same name in base class only
Ans. Option c
Explanation: If a member function is defined in base class and again in derived class, it is said to be overridden as per the definition given in the derived class. As the preference is given more to the local members and when the derived class object calls that function, the definition from the derived class is used.
Ques. Which feature of OOP is exhibited by the function overriding? (1 mark)
a) Polymorphism
b) Encapsulation
c) Abstraction
d) Inheritance
Ans. Option a
Explanation: Function overriding exhibits Polymorphism. Polymorphism as stated exhibits that same named functions can have multiple functionalities.
Ques. Which feature in OOP is used to allocate additional functions to a predefined operator in any language? (1 mark)
a) Function Overloading
b) Function Overriding
c) Operator Overloading
d) Operator Overriding
Ans. Option c
Explanation: The feature in. OOP used to allocate additional functions to a predefined operator in any language is Operator Overloading. There is no term such as 'Operator Overriding'. Moreover, Function overloading or Overriding has no such thing as allocating additional features to the operator.
Ques. Which feature comes under compile time polymorphism? (1 mark)
a) Method overloading
b) Constructor overloading
c) Method overriding
d) Both a and b
e) Both a and c
Ans. Option d
Explanation: Both method overloading and constructor overloading can be done in compile-time polymorphism. This is because the compiler resolves overloaded methods at compile time. In simple terms, the compiler can choose which overloaded method or constructor to call at compile time.
Ques. Which of the following is a type of polymorphism in Java? (1 mark)
a) Compile time polymorphism
b) Execution time polymorphism
c) Multiple polymorphism
d) Multilevel polymorphism
Ans. Option a
Explanation: In Java there are two types of Polymorphism- Runtime (Dynamic) Polymorphism and Compile Time (Static) Polymorphism.
Ques. When is method overloading determined? (1 mark)
a) At run time
b) At compile time
c) At coding time
d) At execution time
Ans. Option b
Explanation: Method overloading produces Compile Time Polymorphism. This states that the compiler will call the method at Compile time only.
Ques. When Overloading does not occur? (1 mark)
a) More than one method with same name but different method signature and different number or type of parameters
b) More than one method with same name, same signature but different number of signature
c) More than one method with same name, same signature, same number of parameters but different type
d) More than one method with same name, same number of parameters and type but different signature
Ans. Option c
Explanation: Overloading occurs in two cases:-
- when more than one method with same name but different constructor are there
- when the same signature but different number of parameters and/or parameter type are used.
For Latest Updates on Upcoming Board Exams, Click Here: https://t.me/class_10_12_board_updates
Check-Out:






Comments