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}
feedAnimals(animals)
}
func feedAnimals(animals []Animal) {
for _, animal := range animals {
animal.feed()
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: