package main

import "fmt"

type Animal interface {
    feed()
}

type Dog struct {
    name string
}

func (d *Dog) feed() {
    fmt.Println(d.name, "the dog eats")
}

type Cat struct {
    name string
}

func (c *Cat) feed() {
    fmt.Println(c.name, "the cat eats")
}

func main() {   
    var jake Animal = &Dog{"Jake"}
    var kam Animal = &Cat{"Kaminari"}
    animals := []Animal{jake, kam}    
    feedAnimal(animals)
}

func feedAnimal(animals []Animal) {
    for _, animal := range animals {
        
        // here is where runtime polymorphism happens
        animal.feed() 
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: