Go没有像C++类中的private protected public关键字,而是根据成员的首字母大小写来决定是否对其他包(package)可见;
首字母大写:公开,可见;
首字母小写:私有,其他包不可访问;
package "mytest"
type Rect struct{ //公开,可被外部访问
Width,Height float64
}
func (r Rect) area() float64{ //方法私有,不可包外访问,只能本包访问
return 0.0
}
func (r Rect) Round() float64{ //方法公开,可被访问
return 0.0
}