初级傻瓜式接口与继承

昨天才知道接口和继承的妙用……tql这个东西

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package main

import "fmt"

type person interface {
greet()
byebye()
}

type student struct {
name string
}

func (s student) greet() {
fmt.Println("Hello. How are you? I am "+s.name+".")
}

func (s student) byebye() {
fmt.Println("Bye bye.")
}

func chatWith(p person) {
p.greet()
p.byebye()
}
func main() {
chatWith(student{name: "Jack"})
}
打赏
  • © 2018-2020 poorpool
  • Powered by Hexo Theme Ayer
    • PV:
    • UV:

请我喝杯草莓芝士奶盖吧~

支付宝
微信