go方法重载

来源:互联网 发布:数据库安全测试工具 编辑:程序博客网 时间:2024/06/05 19:21
package mainimport "fmt"//about receiver functiontype Student struct {    Human    school string}type Employer struct {    Human    company string}type Human struct {    name  string    age   int    phone string}//implement Human methodfunc (h *Human) SetName(name string) {    fmt.Print("human")    h.name = name}func (h *Human) SetAge(age int) {    h.age = age}func (h *Human) SetPhone(phone string) {    h.phone = phone}func (h *Human) GetInfo() Human {    return *h}func (s *Student) SetName(name string) {    fmt.Print("student")    /*about here we can use two wanys to change the value ,so ,how different there ?????*/    s.name = name    //s.Human.name = name}//在go中也有方法的重写和继承func main() {    s := Student{}    s.SetPhone("18755201184")    s.SetName("tsong")    s.SetAge(26)    fmt.Print(s.GetInfo())}
0 0