Files
go-study/demo/demo3.go
2024-08-01 23:40:06 +08:00

38 lines
503 B
Go

package main
import "fmt"
type Animal struct {
Age int
Weight float32
}
func (an *Animal) shou() {
fmt.Println("打击")
}
func (an *Animal) showinfo() {
fmt.Println("动物的体重", an.Age, an.Weight)
}
type Cat struct {
Animal
Age int
}
func (c *Cat) showInfo() {
fmt.Println("动物体重", c.Age, c.Weight)
}
// 对cat绑定特有的方法
func (c *Cat) rs() {
fmt.Println("我是小猫")
}
func main() {
cat := &Cat{}
cat.Weight = 10
cat.Animal.Age = 30
fmt.Println(cat)
}