This commit is contained in:
2024-08-01 23:40:06 +08:00
commit 1adca2ffe6
17 changed files with 469 additions and 0 deletions

26
demo/p2.go Normal file
View File

@@ -0,0 +1,26 @@
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
}