package main
import "fmt"
type Animal struct {
name string
}
func (a *Animal) eat() {
fmt.Printf("%s is eating!\n", a.name)
}
func (a *Animal) sleep() {
fmt.Printf("%s is sleeping!\n", a.name)
}
type Dog struct {
Kind string
*Animal
}
func (d *Dog) bark() {
fmt.Printf("%s is barking ~\n", d.name)
}
type Cat struct {
*Animal
}
func (c *Cat) climbTree() {
fmt.Printf("%s is climb tree ~\n", c.name)
}
func main() {
d1 := &Dog{
Kind: "金毛",
Animal: &Animal{
name: "旺财",
},
}
d1.eat()
d1.bark()
c1 := &Cat{
Animal: &Animal{
name: "喵喵",
},
}
c1.sleep()
c1.climbTree()
}