package main
import (
"fmt"
"math"
)
type rect struct {
width, height float32
}
type cir struct {
r float32
}
type myInt int64
func (a myInt) area() myInt {
return a
}
func (a *rect) area() float32 {
a.height = 12
return (*a).height * (*a).width
}
func (a cir) area() float32 {
a.r = 1
return (a).r * (a).r * math.Pi
}
func main() {
r1 := rect{10, 10}
r2 := cir{10}
r3 := myInt(999)
fmt.Println(r1.area())
fmt.Println(r2.area())
fmt.Println(r3.area())
fmt.Println("Hello World")
fmt.Println(r1.height)
fmt.Println(r2.r)
}
有疑问加站长微信联系(非本文作者)