Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1self._balance = 0 | AA protected attribute: one underscore tells other code it is meant for the class and its subclasses only | |
| 2self.__pin = 1234 | Bdef __check_pin(self): | |
| 3Public for the interface: a method other code is meant to call is given a plain name | CA private attribute: two underscores make it internal data that only this class should use | |
| 4Private for internal data: a helper that only the class itself needs is hidden with two underscores | Ddef deposit(self, amount): | |
| 5self.__balance = 0 # a Savings subclass must read balance directly | EA method that other code must call is marked private. It should be public (get_name) because it is part of the interface. | |
| 6def __get_name(self): return self.name # main code calls acc.__get_name() | FBalance is private, so the subclass cannot easily use it. It should be protected (_balance) because subclasses need access. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
access modifier — Marks a class member as public (name), protected (_name) or private (__name), so the class exposes only what other code needs.class Account:
def setup(self):
self.__balance = 0class Pet:
def setup(self):
self._name = 'Rex'class Account:
def deposit(self, amount):
self.__balance += amountclass Atm:
def __check(self, pin):
return pin == self.pinclass Dog(Pet):
def speak(self):
print(self._name)