202410151618
Status: #idea
Tags: #object_oriented_programming #design_patterns #software_engineering #computer_science
# Compile-time polymorphism
In compile-time polymorphism, a single class may implement multiple methods with different signatures. For example, we may implement an `add(a, b)` method for adding two numbers, and another method `add(a,b,c)` for adding three numbers (see example below). When using these methods in code, the method signature determines which method is invoked at compile time.
```python
class MathOperations:
def add(self, a: int, b: int):
return a + b
def add(self, a: int, b: int, c: int): # Overloaded method
return a + b + c
```
---
# References