Skip to content

Instantly share code, notes, and snippets.

@pallat
Last active February 17, 2016 04:41
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 pallat/bf84f209d1611e78bd64 to your computer and use it in GitHub Desktop.
Save pallat/bf84f209d1611e78bd64 to your computer and use it in GitHub Desktop.
override method in go
package main
import "fmt"
type car interface {
color() string
model() string
}
type toyota struct{}
func (t *toyota) color() string {
return "silver"
}
func (t *toyota) model() string {
return "Fortuner"
}
func tell(c car) {
fmt.Println(c.model(),c.color())
}
type honda struct {
*toyota
}
func (h *honda) model() string {
return "CRV"
}
func main() {
tell(&toyota{})
tell(&honda{})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment