Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Method Overriding in Go
package main
import "fmt"
type foo struct{}
func (f foo) Start() {
fmt.Println("Foo Started")
}
func (f foo) Call() {
fmt.Println("Foo Called")
}
func (f baz) Call() {
fmt.Println("Baz Called")
}
type baz struct {
foo
}
func main() {
foo{}.Call() // This output: Foo Called
foo{}.Start() // This output: Foo Started
baz{}.Call() // This outputs: Baz Called
baz{}.Start() // This outputs: Foo Started
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.