package main import "fmt" // method 方法继承 // DefinedStruct 定义结构体 // Person 定义 type Person struct { name string gender string } // Programmer 定义程序员结构体 type Programmer struct { Person wages float64 } // FreeLancer 定义自由职业者结构体 type FreeLancer struct { Person wages float64 } // DefinedMethod 定义方法 func (p *Person) DefinedMethod() { fmt.Println("This is Person'S Message:", p.name, p.gender) } // MethodRewrite 方法的重写 // FreeLancerMethod对DefinedMethod的方法进行重写 func (f *FreeLancer) MethodRewrite() { fmt.Println("对DefinedMethod的方法进行重写", "My Name Is", f.name, "I am A", f.gender, "I have", f.wages, "Money") } func main() { var pro = Programmer{Person{"Joker Even", "Man"}, 30000000} var fre = FreeLancer{Person{"Joker Even", "Man"}, 300000000} pro.DefinedMethod() fre.DefinedMethod() // 进行重写之后的东西 fre.MethodRewrite() }