animal.go 310 B

1234567891011121314151617181920212223242526272829
  1. package model
  2. import "fmt"
  3. //多态
  4. type Live interface {
  5. run()
  6. }
  7. type People struct {
  8. name string
  9. }
  10. type Animal struct {
  11. name string
  12. }
  13. func (p *People) run() {
  14. fmt.Printf("%v在跑步", p.name)
  15. }
  16. func (a *Animal) run() {
  17. fmt.Printf("%v在跑步", a.name)
  18. }
  19. func allrun(live Live) {
  20. live.run()
  21. }