Guest User

Untitled

a guest
Jun 19th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. )
  6.  
  7. type Square struct {
  8. side float64
  9. }
  10.  
  11. func (s Square) area() float64 {
  12. return s.side * s.side
  13. }
  14.  
  15. type Circle struct {
  16. radius float64
  17. }
  18.  
  19. func (c Circle) area() float64 {
  20. return 2 * 3.1416 * c.radius * c.radius
  21. }
  22.  
  23. type Shape interface {
  24. area() float64
  25. }
  26.  
  27. func info(s Shape) {
  28. fmt.Println(s)
  29. fmt.Println(s.area())
  30. }
  31.  
  32. func main() {
  33. s := Square{10}
  34. c := Circle{10}
  35. info(s)
  36. info(c)
  37. }
Add Comment
Please, Sign In to add comment