-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinherit.py
More file actions
39 lines (28 loc) · 775 Bytes
/
inherit.py
File metadata and controls
39 lines (28 loc) · 775 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
30
31
32
33
34
35
36
37
38
#inheritance example
class Parent:
parentAttr = 100
def _init_(self):
print ("calling parent contructor")
def parentMethod(self):
print ("Calling parent mehtod")
def demo(self):
print ("parent demo")
def setAttr(self,attr):
Parent.parentAttr = attr
def getAttr(self):
print ("Parent Attribute :",Parent.parentAttr)
class Child(Parent):
def _init_(self):
print("Calling child contructor")
def demo(self):
print ("Child demo")
def childMethod(self):
print ("Calling child method")
c= Child() #Instance of child
c.childMethod() # Child call its method
c.parentMethod() # calls parent's method
c.setAttr(200) # again call parent method
c.getAttr() # call parent method
c.demo()
c = Parent()
c.parentMethod()