Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- )
- type Square struct {
- side float64
- }
- func (s Square) area() float64 {
- return s.side * s.side
- }
- type Circle struct {
- radius float64
- }
- func (c Circle) area() float64 {
- return 2 * 3.1416 * c.radius * c.radius
- }
- type Shape interface {
- area() float64
- }
- func info(s Shape) {
- fmt.Println(s)
- fmt.Println(s.area())
- }
- func main() {
- s := Square{10}
- c := Circle{10}
- info(s)
- info(c)
- }
Add Comment
Please, Sign In to add comment