Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumGostruct embedding and promotionSingle-choice MCQ

A struct embeds a pointer to an interface-implementing type so the outer type satisfies the interface via promotion. If that embedded pointer is nil when a promoted method is invoked, what happens?

type Greeter interface{ Greet() string } type impl struct{ name string } func (i *impl) Greet() string { return "hi " + i.name } type Wrapper struct{ *impl } func main() { var g Greeter = Wrapper{} // embedded *impl is nil _ = g.Greet() }