package main
import "fmt"
//接口
//本质上是一个指针
type Animal interface {
Sleep()
GetColor() string
}
//具体的类
type Cat struct {
color string
}
func (this *Cat) Sleep() {
fmt.Println("cat sleep...")
}
func (this *Cat) GetColor() string {
return this.color
}
func showAnimal(animal Animal) {
animal.Sleep()
fmt.Println(animal.GetColor())
}
func main() {
var animal Animal
animal = &Cat{"black"} //多态
animal.Sleep()
fmt.Println("-----------------------")
cat:=Cat{"white"}
showAnimal(&cat) //对象地址传递
}