1. package main
    2. import "fmt"
    3. type Human struct {
    4. name string
    5. sex string
    6. }
    7. func (this *Human) Eat() {
    8. fmt.Println("human.eat...")
    9. }
    10. func (this *Human) Walk() {
    11. fmt.Println("human.walk...")
    12. }
    13. type SuperMan struct {
    14. Human //继承了human类的方法
    15. level int
    16. }
    17. func(this *SuperMan) Eat(){
    18. fmt.Println("superman.eat")
    19. }
    20. func (this *SuperMan) Fly() {
    21. fmt.Println("superman.fly")
    22. }
    23. func (this *SuperMan) Print() {
    24. fmt.Println(this.name,this.sex,this.level)
    25. }
    26. func main() {
    27. h:=Human{"zhangsan","female"}
    28. h.Eat()
    29. h.Walk()
    30. //s:=SuperMan{Human{"lisi","male"},88}
    31. var s SuperMan
    32. s.name = "lisi"
    33. s.sex = "male"
    34. s.level = 88
    35. s.Walk()
    36. s.Eat()
    37. s.Fly()
    38. s.Print()
    39. }