Sobes.tech
Junior — Middle

How do methods differ in programming if their names start with an uppercase or lowercase letter?

sobes.tech AI

Answer from AI

In Go (Golang), the case of the first letter of a method or function name determines its visibility:

  • If the name starts with an uppercase letter, the method or function is exported and accessible from other packages.
  • If the name starts with a lowercase letter, the method or function is unexported and only accessible within the package.

For example:

package example

type MyStruct struct {}

func (m MyStruct) ExportedMethod() {}  // accessible from other packages
func (m MyStruct) unexportedMethod() {} // accessible only within the package example

This simple rule helps manage scope and encapsulation in Go.

How do methods differ in programming if their names… - sobes.tech