Skip to content

Instantly share code, notes, and snippets.

@vaskoz
Created February 28, 2014 16:42
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 vaskoz/9274413 to your computer and use it in GitHub Desktop.
Save vaskoz/9274413 to your computer and use it in GitHub Desktop.
Embedded Structs interview question
package main
import "fmt"
type A struct{}
type B struct {
A
}
func (a A) HiThere() {
fmt.Println(a.secret())
}
func (a A) secret() string {
return "Hi there I'm A"
}
func (b B) secret() string {
return "Hi there I'm B"
}
func main() {
a := A{}
b := B{}
a.HiThere()
b.HiThere()
}
// What is printed and why?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment