-
Notifications
You must be signed in to change notification settings - Fork 195
Expand file tree
/
Copy pathmethod_overloading.py
More file actions
29 lines (24 loc) · 846 Bytes
/
method_overloading.py
File metadata and controls
29 lines (24 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""
Method Overloading allows different methods to have the same name,
but different signatures where the signature can differ by the number of
input parameters or type of input parameters, or a mixture of both.
Method overloading is also known as Compile-time Polymorphism, Static Polymorphism, or Early binding in Java.
In Method overloading compared to parent argument, child argument will get the highest priority.
Below is an example which demonstrates method overloading
"""
# First product method.
# Takes two argument and print their
# product
def product(a, b):
p = a * b
print(p)
# Second product method
# Takes three argument and print their
# product
def product(a, b, c):
p = a * b*c
print(p)
# Uncommenting the below line shows an error
# product(4, 5)
# This line will call the second product method
product(4, 5, 5)