Created
August 31, 2021 14:54
-
-
Save ankit92ios/279b391bb9eb8ac8a9d39cf8709a252a to your computer and use it in GitHub Desktop.
This file contains 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
//An exampple of Polymorphism in Swift | |
class A{ | |
func makeSound(){ | |
print("from A") | |
} | |
} | |
class B : A{ | |
override func makeSound(){ | |
print("from B") | |
} | |
} | |
class C: A { | |
override func makeSound(){ | |
print("from A") | |
} | |
} | |
let arr = [B(), C()] | |
for each in arr{ | |
each.makeSound() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment