Skip to content

Instantly share code, notes, and snippets.

@agoiabel
Created January 11, 2018 22:44
Show Gist options
  • Save agoiabel/c4114dfdc7b35584f0d8dc344b15fd53 to your computer and use it in GitHub Desktop.
Save agoiabel/c4114dfdc7b35584f0d8dc344b15fd53 to your computer and use it in GitHub Desktop.
class Youtuber: Person {
let channelName: String
var subscribers: Int
//we need to pass in the name & age of the Youtuber Person
init(channelName: String, subscribers: Int, name: String, age: Int) {
self.channelName = channelName
self.subscribers = subscribers
//we use this to initialise the Person from within the subclass
super.init(name: String, age: Int)
}
/** This will override the celebrateBirthday in the superclass */
override func celebrateBirthday() {
self.age += 1
print("Hi, happy birthday from ur youtube subscribers")
}
}
Agoi: Person = Person(name: "Adeyemi", age: 27)
Agoi.celebrateBirthday() //Happy birthday Adeyemi
Abel: Youtuber = Youtuber(channelName:"Swift",subscribers:32,name:"Abel",age:27)
Abel.celebrateBirthday() //Hi, happy birthday from ur youtube subscribers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment