Last active
February 17, 2016 04:41
-
-
Save pallat/bf84f209d1611e78bd64 to your computer and use it in GitHub Desktop.
override method in go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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