package mainimport "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 Animalanimal = &Cat{"black"} //多态animal.Sleep()fmt.Println("-----------------------")cat:=Cat{"white"}showAnimal(&cat) //对象地址传递}
