mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 07:23:28 +08:00
29 lines
400 B
Go
Executable File
29 lines
400 B
Go
Executable File
// magic.go
|
|
package main
|
|
|
|
import "fmt"
|
|
|
|
type Base struct{}
|
|
|
|
func (Base) Magic() { fmt.Print("base magic ") }
|
|
|
|
func (self Base) MoreMagic() {
|
|
self.Magic()
|
|
self.Magic()
|
|
}
|
|
|
|
type Voodoo struct {
|
|
Base
|
|
}
|
|
|
|
func (Voodoo) Magic() { fmt.Println("voodoo magic") }
|
|
|
|
func main() {
|
|
v := new(Voodoo)
|
|
v.Magic()
|
|
v.MoreMagic()
|
|
}
|
|
/* Output:
|
|
voodoo magic
|
|
base magic base magic
|
|
*/ |