1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| package main import "fmt"
type Hero struct { Name string Ad int Level int }
func (this Hero) Show() { fmt.Println("Name : ", this.Name) fmt.Println("Ad : ", this.Ad) fmt.Println("Level : ", this.Level) } func (this Hero) GetName() string { return this.Name } func (this *Hero) SetName(name string) { this.Name = name } func main() { hero := Hero{ Name: "freezing", Ad: 33, Level: 1} hero.Show() hero.SetName("rebecca") hero.Show() }
|