Overloading
Overloading is the ability to create multiple methods of the same name with different implementations.
Python Example
A class can implement certain operations that are invoked by special syntax (such as arithmetic operations or subscripting and slicing) by defining methods with special names. This is Python’s approach to operator overloading, allowing classes to define their own behavior with respect to language operators.
For more Python class related examples, see:
# Define a class containing overloading logic. class CustomPrint: # Define a method that changes its behavior depending on parameter(s) provided. def print_text(self, input_text=None): if input_text is not None: print(input_text) else: print("No text provided.") # Instantiate a CustomPrint object. custom_print = CustomPrint() # Use the custom_print object is different ways. custom_print.print_text("sample text") custom_print.print_text()