// Employee重载Human的Sayhi方法 func(e *Employee) SayHi() { fmt.Printf("Hi, I am %s, I work at %s. Call me on %s\n", e.name, e.company, e.phone) //此句可以分成多行 }
//Student实现BorrowMoney方法 func(s *Student) BorrowMoney(amount float32) { s.loan += amount // (again and again and...) }
//Employee实现SpendSalary方法 func(e *Employee) SpendSalary(amount float32) { e.money -= amount // More vodka please!!! Get me through the day! }
// 定义interface type Men interface { SayHi() Sing(lyrics string) Guzzle(beerStein string) }
type YoungChap interface { SayHi() Sing(song string) BorrowMoney(amount float32) }
type ElderlyGent interface { SayHi() Sing(song string) SpendSalary(amount float32) }