Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import "fmt"
- var barsik Cat
- var blueBird Bird
- func main() {
- barsik.Fed = false
- blueBird.Hungry = true
- fmt.Println("Барсик накормлен?", barsik.Fed)
- feedAnimal(&barsik)
- fmt.Println("Барсик накормлен?", barsik.Fed)
- fmt.Println("Blue Bird голодная?", blueBird.Hungry)
- feedAnimal(&blueBird)
- fmt.Println("Blue Bird голодная?", blueBird.Hungry)
- }
- type Cat struct {
- Fed bool
- }
- type Bird struct {
- Hungry bool
- }
- func (c *Cat) Feed() {
- c.Fed = true
- }
- func (b *Bird) Feed() {
- b.Hungry = false
- }
- type Animal interface {
- Feed()
- }
- func feedAnimal(ani Animal) {
- ani.Feed()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement