79254542

Date: 2024-12-05 11:50:13
Score: 1.5
Natty:
Report link

building upon what @Snorik wrote, just want to clarify terminology respecting Python:

  1. Python, by default, does not support method overloading. So you either can: (a) "cheat" your way with if-elif-else, (b) use default arguments none or (c) use the decorator dispatch. For more info and code examples on the decorator check the following link (https://www.geeksforgeeks.org/python-method-overloading/)

  2. Overriding is what happens in Python by default. That is exactly what is happening in your first example of Python code. Now overriding is useful when there are multiple classes sharing the same method name, or when a parent method isn't suited for the needs of a child class and requires modification. Check this link for further examples and code (https://www.w3schools.com/PYTHON/python_polymorphism.asp).

Now for a comparison of Java and Python Polymorphism check the table.

|                         |     Python          |      Java

|   operator overloading  |     yes             |       no
|   (+, -, * :)           |  within each class  |
|                         |  using __add__      |
|                         |  for +, __sub__ for |
|                         |  - and so on        |

|   method overloading    |   no (by default)   |    yes, by default
|                         |  workaround with    |
|                         |  the @dispatch      |
|                         | decorator           |

|   method overriding     |   yes, by default   | not by default, but in
|                         |                     | the context of child
|                         |                     | classes that override
|                         |                     | inherited methods from 
|                         |                     | parent classes

Hope this helps.

Reasons:
  • Blacklisted phrase (1): this link
  • Whitelisted phrase (-1): Hope this helps
  • RegEx Blacklisted phrase (1): Check this link
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @Snorik
  • Low reputation (1):
Posted by: Manuel Denegri Willms