package main
import (
“fmt”
)
定义类
type Eat struct {
Face string
Eye string
Hand string
Mouse string
}
定义类方法 不可修改
func (e Eat) Food() {
fmt.Print(“eat sequence is:\n”)
fmt.Print(" " + e.Eye + " “)
fmt.Print(” " + e.Hand + " “)
fmt.Print(” " + e.Mouse + " “)
fmt.Print(”\neat end")
}
定义类方法 可修改值
func (e *Eat) SetValue(face string, eye string, hand string, mouse string) {
e.Eye = eye
e.Hand = hand
e.Mouse = mouse
e.Face = face
}
使用类
func main(){
var Pe Eat
Pe.SetValue(“face”, “eye”, “hand”, “mouse”)
Pe.Food()
}