GP44. 动物和老虎
描述
输入描述
无输出描述
Go 解法, 执行用时: 2ms, 内存消耗: 904KB, 提交时间: 2022-06-12
package main import ( "fmt" ) type animal interface{ sleep() eat() } type tiger struct { } func (t *tiger) sleep() { fmt.Println("sleep") } func (t *tiger) eat() { fmt.Println("eat") } func main() { t := tiger{} t.sleep() t.eat() }
Go 解法, 执行用时: 2ms, 内存消耗: 1060KB, 提交时间: 2022-07-10
package main import ( "fmt" ) type animal interface { sleep() eat() } type tiger struct { } func ( t tiger)sleep() { fmt.Println("sleep") } func (t tiger)eat() { fmt.Println("eat") } func main() { t := tiger{ } t.sleep() t.eat() }
Go 解法, 执行用时: 2ms, 内存消耗: 1100KB, 提交时间: 2022-06-09
package main import ( "fmt" ) type animal interface{ sleep() eat() } type tiger struct{} func (tiger)sleep(){ fmt.Println("sleep") } func (tiger)eat(){ fmt.Println("eat") } func main() { var t tiger t.sleep() t.eat() }
Go 解法, 执行用时: 2ms, 内存消耗: 1188KB, 提交时间: 2022-06-17
package main import ( "fmt" ) type Animal interface { sleep() eat() } type Tiger struct { } func (this Tiger) sleep() { fmt.Println("sleep") } func (this Tiger) eat() { fmt.Println("eat") } func main() { var tiger *Tiger = &Tiger{} tiger.sleep() tiger.eat() }
Go 解法, 执行用时: 2ms, 内存消耗: 1188KB, 提交时间: 2022-06-15
package main import ( "fmt" ) type animal interface{ sleep() eat() } type tiger struct{ } func(tiger) sleep(){ fmt.Println("sleep") } func(tiger) eat(){ fmt.Println("eat") } func main() { var t tiger t.sleep() t.eat() }