Go ਦੇ ਕੋਲ inheritance ਨਹੀਂ ਹੈ — ਇਸ ਦੀ ਬਜਾਏ ਇਹ struct embedding ਦੁਆਰਾ composition ਵਰਤਦਾ ਹੈ। ਇੱਕ struct (ਜਾਂ interface) ਨੂੰ ਦੂਜੇ ਦੇ ਅੰਦਰ embed ਕਰ ਕੇ، outer type ਨੂੰ inner type ਦੇ fields ਅਤੇ methods ਸਿੱਧੇ ਹਾਸਲ ਹੁੰਦੇ ਹਨ۔ ਇਹ Go ਦੀ "has-a" composition کو "is-a" inheritance پر ترجیح دیتے ہوئے code reuse کے لیے جواب ہے۔
Struct کو embed ਕਰਨਾ
Animal {
Name
}
Eat() {
a.Name +
}
Dog {
Animal
Breed
}
d := Dog{
Animal: Animal{Name: },
Breed: ,
}
fmt.Println(d.Name)
fmt.Println(d.Eat())
