Created
May 29, 2017 09:25
-
-
Save abhimuralidharan/c2fe436dbf41da7c83c21984e9c81565 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Player { | |
| static var totalNumberOfPlayers = 0 | |
| var name:String | |
| init(name:String) { | |
| Player.totalNumberOfPlayers += 1 | |
| self.name = name | |
| } | |
| static func printTotalNumberOfPlayers() { | |
| print("Function log --> Total no of players: \(Player.totalNumberOfPlayers)") | |
| } | |
| class func printGameName() { | |
| print("Road runner") | |
| } | |
| } | |
| let a = Player(name: "abhi") | |
| let b = Player(name: "joe") | |
| print("Total no of players: \(Player.totalNumberOfPlayers)")// prints Total no of players: 2 | |
| Player.printTotalNumberOfPlayers() // print Function log --> Total no of players: 2 | |
| class Enemy: Player { | |
| override class func printGameName() { | |
| super.printGameName() | |
| print("Super mario") | |
| } | |
| // override static func printTotalNumberOfPlayers() { //error: cannot override static method | |
| // print("Function log --> Total no of players: \(Player.totalNumberOfPlayers)") | |
| // } | |
| } | |
| Enemy.printGameName() prints Road runner and Super mario as super method is also called |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment