Question 1[2 marks]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
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 False |
Question 2[4 marks]
Explain using an example from the above code for the Padlock class, what is meant by encapsulation.

Solution...
The solution for this challenge is available to full members!Find out how to become a member:
➤ Members' Area