use_person2.go 267 B

1234567891011121314
  1. package main
  2. import (
  3. "./person"
  4. "fmt"
  5. )
  6. func main() {
  7. p := new(person.Person)
  8. // error: p.firstName undefined (cannot refer to unexported field or method firstName)
  9. // p.firstName = "Eric"
  10. p.SetFirstName("Eric")
  11. fmt.Println(p.FirstName()) // Output: Eric
  12. }