SHARE
TWEET

Untitled

a guest Jan 16th, 2020 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. type person struct {
  6.     name string
  7.     age  int
  8. }
  9.  
  10. type woman struct {
  11.     person
  12.     husband string
  13.     husbandAge int
  14.     name string
  15. }
  16.  
  17. type Person interface {
  18.     getName() string
  19.     getPersonName() string
  20. }
  21.  
  22. func (w woman) getName() string {
  23.     return w.name
  24. }
  25.  
  26. func (w woman) getPersonName() string {
  27.     return w.person.name
  28. }
  29.  
  30. func (p person) getName() string {
  31.     return p.name
  32. }
  33.  
  34. func main() {
  35.     w := woman{}
  36.     w.age = 25
  37.     w.husband = "Ivan"
  38.     w.husbandAge = 26
  39.     w.person.name = "Tania"
  40.     w.name = "Yulia"
  41.     t := woman{}
  42.     t.age = 45
  43.     t.husband = "Petya"
  44.     t.husbandAge = 30
  45.     t.person.name = "Natasha"
  46.     t.name = "Yana"
  47.     d := []Person{}
  48.  
  49.     d = append(d, w)
  50.     d = append(d, t)
  51.     for _, info := range d {
  52.         fmt.Println(info.getName())
  53.     }
  54.  
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top