forked from kumaya/python-programs
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstaticMethod_and_classMethod.py
More file actions
Latest commit
66 lines (45 loc) · 1.23 KB
/
Copy pathstaticMethod_and_classMethod.py
File metadata and controls
66 lines (45 loc) · 1.23 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# test program for the concept of static method and class method
classparent(object):
@staticmethod
defstatic_method(x):
print"parent", x
@classmethod
defclass_method(cls, x):
print"parent", cls, x
defnormal_method(self, x):
print"parent", self, x
classchild1(parent):
# def static_method(x):
# print "child1", x
defclass_method(cls, x):
print"child1", x
defnormal_method(self, x):
print"child1", self, x
classchild2(parent):
@staticmethod
defstatic_method(x):
print"child2", x
# @classmethod
# def class_method(cls, x):
# print "child2", cls, x
defnormal_method(self, x):
print"child2", self, x
obj_child1=child1()
obj_child2=child2()
obj_parent=parent()
obj_child1.normal_method(4)
obj_child2.normal_method(4)
obj_parent.normal_method(4)
# obj_parent.static_method(5)
parent.static_method(5)
child1.static_method(6)
obj_child2.static_method(7)
parent.class_method(8)
# obj_parent.class_method(12)
obj_child1.class_method(8)
child2.class_method(8)
val=child2.class_method(4)
val2=parent.class_method(4)
printisinstance(val, child2)
printisinstance(val, parent)
printisinstance(val2, parent)