In object oriented programming, what is meant by overloading polymorphism (also called compile time or static polymorphism)?

Difficulty: Medium

Correct Answer: The ability to define multiple methods with the same name in the same scope but with different parameter lists, so the compiler chooses which one to call based on the argument types

Explanation:


Introduction / Context:
Polymorphism literally means many forms and is a central idea in object oriented programming. There are different kinds of polymorphism, including overloading polymorphism and overriding polymorphism. Overloading polymorphism is often associated with compile time or static polymorphism. This question asks you to identify what overloading polymorphism means in practical terms when designing classes and methods.


Given Data / Assumptions:

  • We are working in an object oriented language such as C plus plus or Java.
  • The language supports method overloading, where multiple methods share the same name but differ in parameter types or counts.
  • The choice of which overloaded method to call is made by the compiler based on the static types of the arguments.
  • This is distinct from runtime dispatch based on actual object type in overriding polymorphism.


Concept / Approach:
Overloading polymorphism allows a single method name to represent several related operations that differ by parameter type or number. For example, you might have print(int), print(double), and print(String) all in the same class. When you call print with an int argument, the compiler binds the call to the version that takes an int. Because the decision is made at compile time using the static type information, this is known as static or compile time polymorphism. It improves readability by using one conceptual name for several closely related operations.


Step-by-Step Solution:
Step 1: Recognise that overloading refers to multiple declarations with the same name in the same scope but different parameter signatures.Step 2: Understand that the compiler applies overload resolution rules to determine which method version best matches the arguments at each call site.Step 3: Note that once compiled, the call targets are fixed and do not change at runtime based on the dynamic type of the object in the same way as overriding does.Step 4: Compare this with overriding polymorphism, where a subclass provides a new implementation of a superclass method and the actual method invoked depends on the runtime type of the object.Step 5: Conclude that overloading polymorphism is about compile time selection among methods that share a name but differ in parameter lists.


Verification / Alternative check:
You can test overloading polymorphism by writing several overloaded methods and observing which one is called when passing different argument types. If you change only the argument static types, the compiler will choose a different method version, and you can see this in generated bytecode or assembly. If you attempt to overload based only on return type, the compiler will reject it, emphasising that the decision is based on parameter signatures, not return types.


Why Other Options Are Wrong:
Option B describes overriding polymorphism or runtime polymorphism, where subclasses provide their own versions of inherited methods and dispatch depends on the object runtime type. Option C talks about dynamic class loading, which relates to reflection and modularity, not directly to polymorphism. Option D refers to having many instances, which is normal in any program and does not define polymorphism. These options do not capture the specific concept of overloading polymorphism.


Common Pitfalls:
A common pitfall is confusing overloading and overriding because both use the same method name. Developers sometimes expect overloading to behave like overriding and are surprised when the compiler chooses a version based on parameter types rather than dynamic type. Another mistake is overusing overloading for unrelated behaviours, which can make APIs confusing. Good design uses overloading when methods have closely related semantics but differ in the details of their parameters, keeping code clear and discoverable.


Final Answer:
Correct answer: The ability to define multiple methods with the same name in the same scope but with different parameter lists, so the compiler chooses which one to call based on the argument types

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion