Question 1[2 marks]
class Padlock: private key private locked //Constructor for the Padlock class: procedure new(str_key,bool_locked): key = str_key locked = bool_locked public function unlock(combination): if combination==key: locked = False return True else: return False public procedure lock(): locked = True public function getKey(): return key public function setKey(combination): if length(combination)==4: key = combination return True else: return FalseWhat code would you write to instantiate two new padlocks: One called bikeLock that is already locked with a combination of 4321 and one called gardenShedLock that is unlocked with a combination of 1234?
Question 2[4 marks]
Explain using an example from the above code for the Padlock class, what is meant by encapsulation.
![unlock-access](/wp/wp-content/uploads/unlock-access.png)
Solution...
The solution for this challenge is available to full members!Find out how to become a member:
➤ Members' Area