Files

27 lines
340 B
Go
Raw Permalink Normal View History

2024-08-01 23:40:06 +08:00
package main
import "fmt"
type person struct {
Name string
age int
}
// 定义工厂的函数
func NewPerson(name string) *person {
return &person{
Name: name,
}
}
func (p *person) SetAge(age int) {
if age >= 0 && age <= 150 {
p.age = age
} else {
fmt.Println("超出")
}
}
func (p *person) GetAge() int {
return p.age
}