class
This commit is contained in:
parent
a0378efce0
commit
18870edf38
48
bilibili/aceid/struct/class/test.go
Normal file
48
bilibili/aceid/struct/class/test.go
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
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 {
|
||||||
|
// fmt.Println("Name = ", this.Name)
|
||||||
|
// return this.Name
|
||||||
|
// }
|
||||||
|
|
||||||
|
// func (this Hero) SetName(name string) {
|
||||||
|
// this.Name = name
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 方法名首字母大写即为公有方法,首字母小写即为私有方法
|
||||||
|
func (this *Hero) Show() {
|
||||||
|
fmt.Println("Name = ", this.Name)
|
||||||
|
fmt.Println("Ad = ", this.Ad)
|
||||||
|
fmt.Println("Level = ", this.Level)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *Hero) GetName() string {
|
||||||
|
fmt.Println("Name = ", this.Name)
|
||||||
|
return this.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *Hero) SetName(name string) {
|
||||||
|
this.Name = name
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
hero := Hero{Name: "zhang3", Ad: 100, Level: 1}
|
||||||
|
hero.Show()
|
||||||
|
hero.SetName("Aaron")
|
||||||
|
hero.Show()
|
||||||
|
}
|
26
bilibili/aceid/struct/test1/test.go
Normal file
26
bilibili/aceid/struct/test1/test.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
type myint int
|
||||||
|
|
||||||
|
type Book struct {
|
||||||
|
title string
|
||||||
|
auth string
|
||||||
|
}
|
||||||
|
|
||||||
|
func printBook(myBook Book) {
|
||||||
|
fmt.Printf("%v\n", myBook)
|
||||||
|
}
|
||||||
|
|
||||||
|
func changeBook(myBook *Book) {
|
||||||
|
myBook.title = "Learning Golang"
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var book1 Book
|
||||||
|
book1.title = "Golang"
|
||||||
|
book1.auth = "Aaron"
|
||||||
|
changeBook(&book1)
|
||||||
|
printBook(book1)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user