-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path26thInheritanceinPython.py
More file actions
40 lines (20 loc) · 1.17 KB
/
26thInheritanceinPython.py
File metadata and controls
40 lines (20 loc) · 1.17 KB
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
30
31
32
33
34
35
36
37
38
39
40
# ! Inheritance
# * Where one class takes or 'inherits' attributes(variables) or methods(functions) from other classes
class Curry:
def __init__(self, name, temperature):
print('In Class Curry Constructor')
self.name = name
self.temperature = temperature
def display(self):
print('In Class Curry Display')
class Vegetable(Curry): # * This leads to inheritance
def __init__(self, name, temperature, batchno):
self.batchno = batchno
Curry.__init__(self, name, temperature) # * We can initialize the other variables using the other Parent's class's Constructor
print(f'Taken from other class:\nName of Soup: {self.name}\nTemperature of Soup: {self.temperature}\nIs in this Vegetable Class:\nBatchno: {self.batchno}')
def disp(self):
print('In Class Vegetable Disp')
Curry.display(self) # * We can use the Parent Class to call it's function
eng = Vegetable('Tomato Soup', 56, 101) # * When I call this, the constructor of Curry runs first
# eng.disp() # * Can call the method in this class itself
# eng.display() # * Can also call the method present inside Parent Class