-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPractIce.py
61 lines (57 loc) · 1.22 KB
/
PractIce.py
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
'''
#Private Varible(Encapsulation)...!
class A:
def __init__(self,name,age):
self.name=name
self.__age=age
def show(self):
print("Here it is..!")
a=A("Rahul",23)
a__age=54
print(a.name)
print(a._A__age)
#Calling Static method using another method...!
class A:
def __init__(self,a,b):
self.a=a
self.b=b
@staticmethod
def show(a,b):
c=a+b
print(c)
def display(self):
self.show(self.a,self.b)
a,b=int(input()),int(input())
a1=A(a,b)
a1.display()
#Method Overriding(Polymorphism)
class Phone:
def __init__(self,name):
self.name=name
def buy(self):
print("Yes you can buy...!")
class smartPhone(Phone):
def __init__(self,Price):
self.Price=Price
def buy(self):
super().buy()
print("Buy that phone..!",self.Price)
s1=smartPhone(23400)
s1.buy()
'''
#Multiple Inheritance
class A:
def __init__(self,name,age):
self.name=name
self.age=age
def buy(self):
print("Go and buy that...!")
class B:
def buy(self):
print("Ok,I am going to buy...!")
class C(B,A):
def buy(self):
super().buy()
print("--- Buying ---")
c1=C("George Washington",32)
c1.buy()