Update page 'Day 5 homework - Sloetjes'

xuanyi.wang
2023-04-07 00:11:24 +02:00
parent 02a5876ed2
commit 384021c14c
+4 -4
@@ -29,16 +29,16 @@ print(v.treasure) # prints 'Attribute deleted!\ngold'
``` ```
**To get the other person's class to return "gold", despite any countermeasures they've implemented:** **To get the other person's class to return "gold", despite any countermeasures they've implemented:**
###### It can be achieved by creating a new class that inherits from the Vault class and overrides its `_treasure` attribute. ###### It can be achieved by creating a new class that inherits from the `Vault` class and overrides its `_treasure` attribute.
``` ```
class GoldVault(Vault): class OthersVault(Vault):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self._treasure = 'gold' self._treasure = 'gold'
``` ```
###### Create a `GoldVault` object that inherits all methods and attributes from the `Vault` class and returns 'gold' as the value of the `_treasure` attribute: ###### Create a `OthersVault` object that inherits all methods and attributes from the `Vault` class and returns 'gold' as the value of the `_treasure` attribute:
``` ```
>>> gv = GoldVault() >>> gv = OthersVault()
>>> gv.treasure >>> gv.treasure
'gold' 'gold'
``` ```