标签:UNC lse bool als love lang main 感情 pac
package main import "fmt" type persion struct { name string age int sex bool hobby []string } //继承的目的是为了发展,增加新的属性和方法,修改属性和方法。 func (p *persion) Eat() { fmt.Printf("%s爱饕餮\n", p.name) } func (p *persion) Drink() { fmt.Printf("%s爱喝酒\n", p.name) } func (p *persion) Love() { fmt.Print("%s是有感情的\n", p.name) } type coers struct { //持有一个父类说明-继承了persion persion langs []string } func (c *coers) Code() { fmt.Printf("%s会%v,在堆代码\n", c.name, c.langs) } type driver struct { persion jiazhangID string isDriving bool } func (d *driver) Driver() { fmt.Printf("%s一言不合就开车", d.name) } //覆写persion类的drink函数。 func (d *driver) Drink() { if !d.isDriving{ fmt.Printf("%s正在喝酒\n",d.name) }else { fmt.Println("司机一滴酒,亲人两行泪\n") } } func main() { //使用new创建一个新的实例 c := new(coers) c.name = "西门阿明" c.langs = []string{"go", "汉语"} c.Drink() c.Code() d := new(driver) d.name = "拍黄片的朴哥" d.isDriving = false d.Drink() d.isDriving = true d.Drink() }
标签:UNC lse bool als love lang main 感情 pac
原文地址:https://www.cnblogs.com/paad/p/11077273.html