---
# System prepended metadata

title: Untitled

---

```
package main 

import ( 
	"fmt"
) 

type Animal struct {
	name string
	age int
}

func (animal Animal) printDetails() {
	fmt.Println("name: ", animal.name)
	fmt.Println("age: ", animal.age)
}

func (animal Animal) sound() {
	fmt.Println("Animal Sound")
}

type Dog struct {
	animal Animal
}

func (dog Dog) sound() {
	fmt.Println("ghew ghew")
}

type Cat struct {
	animal Animal
}

func (dog Cat) sound() {
	fmt.Println("mew mew")
}

func main() { 

	// animal
	animal := Animal{name: "John", age: 9}
	animal.printDetails()
	animal.sound()
	
	fmt.Println();
	
	// dog
	dog := Dog{Animal{name: "Mike", age: 5}}
	dog.animal.printDetails();
	dog.sound();
	
	fmt.Println();
	
	// cat
	cat := Cat{Animal{name: "Mini", age: 2}}
	cat.animal.printDetails();
	cat.sound();
}
```

