package main
import"fmt"//实现封装、继承、多态//创建接口type Animal interface{msg()}//基类type Pets struct{
name string
age int}//Dog类继承基类type Dog struct{
Pets
color string}//Cat类继承基类type Cat struct{
Pets
color string}//绑定接口的方法func(d *Dog)msg(){
fmt.Println("我是",d.name,"我今年",d.age,"岁了","我喜欢",d.color,"色")}func(c *Cat)msg(){
fmt.Println("我是",c.name,"我今年",c.age,"岁了","我喜欢",c.color,"色")}//封装接口funcdata(a Animal){
a.msg()}funcmain(){
dog := Dog{Pets{"花花",2},"棕"}data(&dog)
cat := Cat{Pets{"肉肉",1},"白"}data(&cat)}