2,190
社区成员
发帖
与我相关
我的任务
分享
type Animal interface {
Sleep()
Age() int
Type() string
}
type Cat struct {
MaxAge int
Owner string
}
func (this *Cat) Sleep() {
fmt.Println("Cat need sleep")
}
func (this *Cat) Age() int {
return this.MaxAge
}
func (this *Cat) Type() string {
return this.Owner
}
/*=======================================================*/
type Dog struct {
MaxAge int
}
func (this *Dog) Sleep() {
fmt.Println("Dog need sleep")
}
func (this *Dog) Age() int {
return this.MaxAge
}
func (this *Dog) Type() string {
return "Dog"
}