-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccess_Modifiers.py
62 lines (48 loc) · 1.62 KB
/
Access_Modifiers.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
# #This program is to illustrate access modifiers of a class
# class super:
# #public data member
# var1 = None
# #protected data member
# _var2 = None
# #private data member
# __var3 = None
# #constructor
# def __init__(self,var1,var2,var3):
# self.var1 = var1
# self._var2 = var2
# self.__var3 = var3
# #public member function
# def displayPublicMembers(self):
# #accessing public data members
# print("Public Data member:",self.var1)
# # protected member function
# def _displayProtectedMembers(self):
# # accessing protected data members
# print("Protected Data member:", self._var2)
# # private member function
# def __displayPrivateMembers(self):
# # accessing private data members
# print("Private Data member:", self.__var3)
# #public member function
# def accessPrivateMembers(self):
# self.__displayPrivateMembers()
# #derive class
# class Sub(super):
# #constructor
# def __init__(self,var1,var2,var3):
# super.__init__(self,var1,var2,var3)
# #public member function
# def accessProtectedMembers(self):
# #accessing protected member functions of super class
# self._displayProtectedMembers()
# #creating objects of the derived class
# obj = Sub("Nexusberry",4,"DSML")
# #calling public member functions of the class
# obj.displayPublicMembers()
# obj.accessProtectedMembers()
# obj.accessPrivateMembers()
# print(obj.var1)
# superobj = super("Nexusberry",4,"DSML")
# # print(superobj.__var3)
# superobj.accessPrivateMembers()
# print(obj._var2)