Skip to content

Instantly share code, notes, and snippets.

@ankit92ios
Created August 31, 2021 14:54
Show Gist options
  • Save ankit92ios/279b391bb9eb8ac8a9d39cf8709a252a to your computer and use it in GitHub Desktop.
Save ankit92ios/279b391bb9eb8ac8a9d39cf8709a252a to your computer and use it in GitHub Desktop.
//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