typeover
curriculum

Curriculum Idioms & ecosystem Embedding exercise 1 · mcq

Embedding

Pick the line that EMBEDS the type Animal into the struct Dog — the syntax that gives Dog access to all of Animal's fields and methods. TypeScript: class Dog extends Animal { breed: string }. Go has no extends; embedding is the composition-based alternative.

TypeScript reference
Pick the idiomatic Go translation

About this theme

Struct embedding gives you composition without inheritance. Embed a type as an unnamed field and its methods get promoted onto the outer struct. This is how Go does "extend a type" — by containing one. The rule: prefer composition; Go literally doesn't give you inheritance to misuse.