Created
February 28, 2014 16:42
-
-
Save vaskoz/9274413 to your computer and use it in GitHub Desktop.
Embedded Structs interview question
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 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