4-3 go to inherit

package main

import "fmt"

type persion struct {
    name  string
    age   int
    sex   bool
    hobby []string
}

// inherit purpose is to develop, adding new properties and methods to modify the properties and methods. 

FUNC (P * persion) Eat. () {
    fmt.Printf ( " % S Love gluttonous \ the n- " , p.name)
}

func (p *persion) Drink() {
    fmt.Printf ( " % S love to drink \ the n- " , p.name)
}
func (p *persion) Love() {
    fmt.Print ( " % S have feelings \ the n- " , p.name)
}

coers of the type struct {
     // hold a parent class description - inherited persion 
    persion
    along [] string
}

func (c *coers) Code() {
    fmt.Printf ( " % S would% v, the code in the stack \ n- " , c.NAME, c.langs)
}

type driver struct {
    persion
    jiazhangID string
    isDriving  bool
}

func (d *driver) Driver() {
    fmt.Printf ( " % S Yiyanbuge car " , d.name)
}

// override function persion drink category. 
FUNC (D * Driver). Drink. () {
     IF ! d.isDriving {
        fmt.Printf ( " % S imbibing \ n- " , d.name)
    }else {
        fmt.Println ( " drivers drop of wine, two lines of relatives of tears \ the n- " )
    }
}

func main() {
    // use new to create a new instance of 
    c: = new (coers)
    c.NAME = " Simon Amin " 
    c.langs = [] String { " Go " , " Chinese " }
    c.Drink()
    c.Code()

    d := new(driver)
    d.name = " Sign porn Pu brother " 
    d.isDriving = to false
    d.Drink()
    d.isDriving = true
    d.Drink()
}

 

Guess you like

Origin www.cnblogs.com/paad/p/11077273.html
4-3