package main
import "fmt"
type Human struct {
name string
sex string
}
func (this *Human) Eat() {
fmt.Println("Human Eat()...")
}
func (this *Human) Walk() {
fmt.Println("Human Walk()...")
}
type Superman struct {
Human // 继承Human类方法
level int
}
// 重新定义父类方法
func (this *Superman) Eat() {
fmt.Println("Superman Eat()...")
}
// 子类的新方法
func (this *Superman) Fly() {
fmt.Println("Superman Fly()...")
}
func (this *Superman) Print() {
fmt.Println("name = ", this.name)
fmt.Println("sex = ", this.sex)
fmt.Println("level = ", this.level)
}
func main() {
h := Human{"zhangsan", "female"}
h.Eat()
h.Walk()
var s Superman
s.name = "lisi"
s.sex = "female"
s.level = 99
s.Eat()
s.Walk()
s.Fly()
s.Print()
}