Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. class Person {
  2.  
  3. var firstName: String
  4. var lastName: String
  5. var zipCode = 12345
  6.  
  7. init(firstName: String, lastName: String) {
  8. self.firstName = firstName
  9. self.lastName = lastName
  10. }
  11.  
  12. func greetings() {
  13. print("Hi, my name is \(firstName) \(lastName)!")
  14. }
  15. }
  16.  
  17. class Employee: Person {
  18.  
  19. var staffNummer: Int
  20.  
  21. init(staffNummer: Int, firstName: String, lastName: String) {
  22.  
  23. self.staffNummer = staffNummer
  24.  
  25. super.init(firstName: firstName, lastName: lastName)
  26.  
  27. zipCode = 12345 //We override to inherited property of the superclass
  28.  
  29. }
  30.  
  31. func identity() {
  32. print("First name: \(firstName), Last name \(lastName), Staff Number \(staffNummer)")
  33. }
  34.  
  35. override func greetings() {
  36. print("Hello, how are you?") //We override the function of the superclass
  37. }
  38. }
  39.  
  40. let christine = Employee(staffNummer: 780, firstName: "Christine", lastName: "Mayer")
  41.  
  42. christine.greetings()
  43. //Output: Hello, how are you?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement