package main
import "fmt"
type Animal interface {
Sound() string
}
type Duck struct {
}
func (duck Duck) Sound() string {
return "Quack"
}
type Cat struct {
}
func (cat Cat) Sound() string {
return "Meo Meo"
}
func main() {
var animal Animal
duck := Duck{}
cat := Cat{}
animal = duck
fmt.Println(animal.Sound())
animal = cat
fmt.Println(animal.Sound())
}
Output
Quack
Meo Meo