Section 9.6 Check Point Questions5 questions
9.6.1
What problem arises in running the following program? How do you fix it?
class A: def __init__(self, i): self.__i = i def main(): a = A(5) print(a.__i) main() # Call the main function
9.6.2
Is the following code correct? If so, what is the printout?
1 def main(): 2 a = A() 3 a.print() 4 5 class A: 6 def __init__(self, newS = "Welcome"): 7 self.__s = newS 8 9 def print(self): 10 print(self.__s) 11 12 main() # Call the main function
9.6.3
Is the following code correct? If not, fix the error.
class A: def __init__(self, on): self.__on = not on def main(): a = A(False) print(a.on) main() # Call the main function
9.6.4
What are the benefits of data hiding? How is it done in Python?
9.6.5
How do you define a private method?