mirror of
https://github.com/MADTeacher/go_basics.git
synced 2025-11-23 21:34:47 +02:00
33 lines
409 B
Go
33 lines
409 B
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
type Person struct {
|
|
name string
|
|
age uint8
|
|
}
|
|
|
|
func (p *Person) getName() string {
|
|
return p.name
|
|
}
|
|
|
|
func (p *Person) getAge() uint8 {
|
|
return p.age
|
|
}
|
|
|
|
func (p *Person) incAge() {
|
|
p.age++
|
|
}
|
|
|
|
func main() {
|
|
alex := &Person{
|
|
name: "Alex",
|
|
age: 26,
|
|
}
|
|
fmt.Printf("Person data: %+v\n", alex)
|
|
alex.incAge()
|
|
fmt.Printf("Person data: %+v\n", alex)
|
|
alex = nil
|
|
alex.incAge()
|
|
}
|