Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.66 KB | None | 0 0
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. var barsik Cat
  6. var blueBird Bird
  7.  
  8. func main() {
  9.     barsik.Fed = false
  10.     blueBird.Hungry = true
  11.     fmt.Println("Барсик накормлен?", barsik.Fed)
  12.     feedAnimal(&barsik)
  13.     fmt.Println("Барсик накормлен?", barsik.Fed)
  14.     fmt.Println("Blue Bird голодная?", blueBird.Hungry)
  15.     feedAnimal(&blueBird)
  16.     fmt.Println("Blue Bird голодная?", blueBird.Hungry)
  17. }
  18.  
  19. type Cat struct {
  20.     Fed bool
  21. }
  22.  
  23. type Bird struct {
  24.     Hungry bool
  25. }
  26.  
  27. func (c *Cat) Feed() {
  28.     c.Fed = true
  29. }
  30.  
  31. func (b *Bird) Feed() {
  32.     b.Hungry = false
  33. }
  34.  
  35. type Animal interface {
  36.     Feed()
  37. }
  38.  
  39. func feedAnimal(ani Animal) {
  40.     ani.Feed()
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement