Skip to content

Instantly share code, notes, and snippets.

@bbengfort
Created October 10, 2014 00:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbengfort/e54e8c816e4df90feb92 to your computer and use it in GitHub Desktop.
Save bbengfort/e54e8c816e4df90feb92 to your computer and use it in GitHub Desktop.
Demonstration of overloading in Go
package main
import (
"fmt"
)
type A struct{
name string
}
func (a *A) method() {
fmt.Printf("In method of an A named %s\n", a.name)
}
type B struct {
A
}
func (b *B) method() {
fmt.Printf("In method of an B named %s\n", b.name)
(&b.A).method()
}
func main() {
a := A{"apple"}
b := new(B)
b.name = "banana"
a.method()
b.method()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment