typeover
curriculum

Curriculum Idioms & ecosystem Embedding exercise 3 · mcq

Embedding

Pick the IDIOMATIC composite-literal syntax to construct a Dog (which embeds Animal) with Name: "Rex" and Breed: "Lab". TypeScript: new Dog("Rex", "Lab"). Go embedded fields use the TYPE NAME as the field name in composite literals.

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.