@@ -14,27 +14,36 @@ class Person:
14
14
def __init__ (self , name , age ):
15
15
self .name = name
16
16
self .age = age
17
- self .country = 'Pakistan'
17
+ self .country = 'Pakistan' # Protected Variable.
18
+ self .__private = 'secret' # Private variable
18
19
19
20
def __str__ (self ):
20
- return 'Hello to Person Class'
21
+ return f 'Hello to Person Class { self . name } '
21
22
22
23
class Employee (Person ):
23
24
# Need to assign Values otherwise through Error.
24
- def __init__ (self ):
25
- Person .name = 'Hassan'
26
- Person .age = '21'
25
+ def __init__ (self , name , age ):
26
+ Person .__init__ (self , name , age )
27
+ Person .name = 'Hassan' # not work
28
+ Person .age = '21' # not work, logic.
29
+
30
+ print (self .country ) # work.
31
+ print (self .__private ) # Through error.
32
+
33
+
34
+
27
35
28
36
@staticmethod
29
37
def show ():
30
38
print ('Its Employee Class' )
31
39
32
40
# Objects / Instance
33
- emp1 = Employee ()
41
+ emp1 = Employee ('hassan' , 22 )
34
42
print (emp1 )
35
43
emp1 .show ()
36
44
print (emp1 .name )
37
- print (emp1 .country ) # Through error. Not recognize.
45
+ print (emp1 .country ) # Now, it works
46
+ print (emp1 .__private ) # Now, it not work, through error.
38
47
39
48
40
49
# ====== Inheritance Super Keyword ======= #
@@ -68,10 +77,10 @@ def is_employee(self):
68
77
# Objects / Instance
69
78
emp1 = Employee ('Ali' , 22 , 'Real Estate Agent' )
70
79
print (emp1 .show ())
71
- print (emp1 )
80
+ print (emp1 ) # gives Hassan
72
81
print (emp1 .is_employee ())
73
82
74
83
75
84
if __name__ == '__main__' :
76
- # inheritance_basics()
77
- super_keyword ()
85
+ inheritance_basics ()
86
+ # super_keyword()
0 commit comments