Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type Animal = ref object of RootObj
- name: string
- age: int
- method vocalize(this: Animal): string {.base.} = "..."
- method ageHumanYrs(this: Animal): int {.base.} = this.age
- type Dog = ref object of Animal
- method vocalize(this: Dog): string = "woof"
- method ageHumanYrs(this: Dog): int = this.age * 7
- type Cat = ref object of Animal
- method vocalize(this: Cat): string = "meow"
- var animals: seq[Animal] = @[]
- animals.add(Dog(name: "Sparky", age: 10))
- animals.add(Cat(name: "Mitten", age: 10))
- for a in animals:
- case a:
- of Dog:
- echo "dog"
- of Cat:
- echo "cat"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement