Class declaration
type Poem struct { Title string Author string intro string }
Golang uses another approach to implement attribute access permissions: if the initial letter of the attribute is capitalized, it can be accessed in other packages, otherwise it can only be accessed in this package. The same goes for class declarations and methods.
Class method declaration
func (poem *Poem) publish() { fmt.Println("poem publish") }
func (poem Poem) publish() { fmt.Println("poem publish") }
The above is the detailed content of Does golang have classes?. For more information, please follow other related articles on the PHP Chinese website!