You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
golang-tutorial/demo/method/method04.go

31 lines
378 B

package main
import (
"fmt"
)
type rectangle struct {
length int
width int
}
func Area(r rectangle) {
fmt.Printf("Area Function result: %d\n", (r.length * r.width))
}
func (r rectangle) Area() {
fmt.Printf("Area Method result: %d\n", (r.length * r.width))
}
func main(){
r := rectangle{
length:10,
width:20,
}
Area(r)
r.Area()
p := &r
//Area(p)
p.Area()
}