DEV Community

Snehasish Konger
Snehasish Konger

Posted on

Method overloading & overriding in Polymorphism

Why Method overloading is called compile-time polymorphism?

Method overloading is a feature of object-oriented programming languages that allows a class to have multiple methods with the same name, as long as they have different parameter lists.

This allows for a more concise and readable implementation, as the same method name can be used to perform different operations depending on the arguments provided.

Method overloading is called compile-time polymorphism because it is resolved at compile time, meaning that the compiler determines which method to call based on the arguments provided at the time the code is compiled. This is in contrast to runtime polymorphism, which is resolved at runtime and allows for a single method to behave differently depending on the type of object it is called on.

In summary, method overloading is called compile-time polymorphism because it is resolved at compile time, meaning that the compiler determines which method to call based on the arguments provided at the time the code is compiled. This is in contrast to runtime polymorphism, which is resolved at runtime.

Why Method overriding is called run-time polymorphism?

Method overriding is a feature of object-oriented programming languages that allows a subclass to provide a specific implementation of a method that is already defined in a superclass.
This allows for runtime polymorphism, where a single method can behave differently depending on the type of object it is called on.

Method overriding is called runtime polymorphism because it is resolved at runtime, meaning that the actual method that is executed is determined based on the type of the object on which the method is called. This is in contrast to compile-time polymorphism, which is resolved at compile time and allows for a class to have multiple methods with the same name as long as they have different parameter lists.

In summary, method overriding is called runtime polymorphism because it is resolved at runtime, meaning that the actual method that is executed is determined based on the type of the object on which the method is called. This is in contrast to compile-time polymorphism, which is resolved at compile time.

Top comments (0)