golang 结构体struct 和接口interface
浏览量:423
package main import "fmt" type Perpro struct { name string sex int age int } type Student struct { Perpro phone int } func (p Perpro) SayHi() { fmt.Println("Hi,my age is",p.age,p.name) } func (s Student) Sing(ly string) { fmt.Println("sing Hi",ly) } type Men interface { SayHi() Sing(ly string) } func main(){ mike := Student{Perpro{"lianghuiju",1,22},13146686224} var i Men i = mike fmt.Println("This is Mike, a Student:") i.SayHi() i.Sing("i like this there") }
输出结果:
神回复
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。