“Go” Language Tutorial-5(Exported Names)

Posted: June 26, 2012 in Go, Language
Tags: , , , , ,

EXPORTED NAMES

 

After importing a package, you can refer to the names it exports.

In Go, a name is exported if it begins with a capital letter.

Foo is an exported name, as is FOO. The name foo is not exported.

Run the code. Then rename math.pi to math.Pi and try it again.

Example :

package main

import (
“fmt”
“math”
)

func main() {
fmt.Println(math.pi)
}

output:

prog.go:9: cannot refer to unexported name math.pi
prog.go:9: undefined: math.pi

after renaming math.pi to math.Pi

package main

import (
“fmt”
“math”
)

func main() {
fmt.Println(math.Pi)
}

output:

3.141592653589793
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s