ENCAPSULATION ============== wrapping up of data and methods into a single module/unit is called as an encapsulation. why encapsulation? ================== 1) Security An organization Accounting section <===============> request marketing/sales section 2) Hiding 3) Reusability of the code is increased. In Java: 3-access modifiers: 1) Public ==> public 2) Private ==> private 3) protected ==> protected In Python: there are no keywords for representing access modifiers. public ==> we can access public data from any where any data and method in class are public by default. private ==> with '__' can always allow to access within the defined class in outside of the class, we cannot. protected ==> with '_' can always allow to access within the defined class and in sub-class also. but not from outside of the class. Note: Encapsulation is possible with either private or protected members only. class publicModifiers: a = 100 b = 200 def __init__(self,p,q): self.p = p self.q = q def printing(self): print("Class Variables are = ",self.a,self.b) print("Instance Variables = ",self.p,self.q) pm = publicModifiers(111,222) print(pm.a) print(pm.b) pm.printing() print(pm.p) print(pm.q) ========================= class privateModifiers: # private data __data1 = 1234 __data2 = "python" # PUBLIC METHOD def met1(self): print("The data of the class are:") print(self.__data1) print(self.__data2) # PRIVATE METHODS def __met2(self): print("Hello") def met3(self): self.__met2() pm = privateModifiers() # print(pm.__data1) pm.met1() # pm.__met2() # privateModifiers.__met2() pm.met3() ================================= class protectedModifiers: # prtected data _data1 = 1212 _data2 = 1221 def m1(self): print(self._data1) print(self._data2) pm = protectedModifiers() print(pm._data1) print(pm._data2) ==================================== Garbage Collection =================== C++ ==> class, object class o1, o2, o3 o1 ==> is using but not o2 and o3 PLAYSTORE CAR RACE GAME ==> 1500KB ASSUME: F1 ==> 300KB ==> CLASS1 ==> O1 F2 ==> 400 KB ==> CLASS2 ==> O2 F3 ==> 300 KB ==> CLASS3 ==> O3 F4 ==> 500KB ==> CLASS4 ==> O4 aSSUME: I like 'F4' while start "F4" ==> o4 ==> run 500kb 700kb 1000kb 1600kb Garbage Collection: ================= Automatic to run the application perfectly and secure the application from errors (out of memory) ==> garbage collection is needed. manual garbage collection: ========================== import gc print(gc.isenabled()) gc.disable() print(gc.isenabled()) gc.enable() print(gc.isenabled())