package visibilityimport "fmt"const PI = 3.145const pi = 3.14const _PI = 3.14var P int = 1var p int = 1func private_function() { fmt.Println("only used in this package!")}func Public_fuction() { fmt.Println("used in anywhere!")}package mainimport ( "visibility" "fmt")func main() { visibility.Public_fuction() //used in anywhere! //visibility.private_function() //不能访问私有函数,无法通过编译 fmt.Println(visibility.P) //1 //fmt.Println(visibility.p) //不能访问私有变量,无法通过编译 fmt.Println(visibility.PI) //3.14 //fmt.Println(visibility.pi) //不能访问私有常量,无法通过编译 //fmt.Println(visibility._PI) //不能访问私有常量,无法通过编译}

posted on 2019-09-03 14:29  ExplorerMan  阅读(1737)  评论(0)  编辑  收藏  举报