12345678910111213141516171819202122232425262728293031323334 |
- package model
- import (
- "fmt"
- )
- //封装
- type People struct {
- name string
- age int
- }
- func (p *People) SetName(name string) {
- p.name = name
- }
- func (p *People) SetAge(age int) {
- p.age = age
- }
- func (p *People) GetName() string {
- return p.name
- }
- func (p *People) GetAge() int {
- return p.age
- }
- func main() {
- peo := new(People)
- peo.SetName("derek")
- peo.SetAge(22)
- fmt.Println(peo.GetName(), peo.GetAge()) //derek 22
- }
|