Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment