-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathD14_Objects.py
More file actions
111 lines (53 loc) · 1.2 KB
/
Copy pathD14_Objects.py
File metadata and controls
111 lines (53 loc) · 1.2 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
"""
#1. conver of local to class values
class Myclass:
def __init__ (self,v1,v2):
print(v1)
print(v2)
self.v1 = v1
self.v2 = v2
def add (self):
print(self.v1+self.v2)
c = Myclass(10,20)
c.add()
#2.
class Myclass:
pass
c=Myclass()
print(c) #addr of obj c
#3.
class Test:
def __str__ (self):
return "Welcome to __str__() Constructor"
t= Test();
print(t)
#4.
class Test:
def __str__(self):
return 10 #cannot pass int, it accepts string only
t = Test()
print(t)
#5. Simple inheritance
class Person: #base class
name = 'ABC'
no = 8149969019
class address(Person): #child class
address = 'Pune'
p=address() #creating obj of address class
print(p.name)
print(p.no)
print(p.address)
"""
#6. Simple inheritance
class Parent:
def m1(self):
print("Parent cl m1")
class Child(Parent):
def m2(self):
print("Child cl m2")
p = Parent()
p.m1()
#p.m2() will give error cz parent cannot access child method
c= Child()
c.m1()
c.m2()