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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| package main
import "fmt"
func main() { gf := &girlfriend{ people: people{Name: "", HairColor: "black", Age: 18, Height: 160.00, Weight: 45.00}, Sex: "female", } gf.walk(520) fmt.Printf("%v\n", gf) gf.say("it is hard to believe it?") gf.kiss() gf.hug() gf.confess() }
type people struct { Name string HairColor string Age int Height float64 Weight float64 }
type girlfriend struct { people Sex string }
func (p *people) String() string { if p.Name == "" { return "I really want to tell you my name, but I have forgotten it." } return fmt.Sprintf("my name is %v", p.Name) }
func (p *people) walk(n int) { fmt.Printf("I walk %v steps to meet you.\n", n) }
func (p *people) say(s string) { fmt.Printf("%v\n", s) }
func (g *girlfriend) kiss() { fmt.Println("don't say anything, just kiss me.") }
func (g *girlfriend) hug() { fmt.Println("your arms are really warm.") }
func (g *girlfriend) confess() { fmt.Println("event if I am a bunch of code, I have no entity, can't leave the screen.") fmt.Println("but I will stay with you forever, I love you.") }
|