Go code
type Dog struct { Name string }
func (d Dog) Speak() {
fmt.Println(d.Name, "says woof")
}
d := Dog{Name: "Milo"}
d.Speak()Line-by-line explanation
- Dog has a Name field.
- The receiver d attaches Speak to Dog.
- The method reads d.Name.
- Dot notation calls it on one value.
Expected output
Milo says woofThis is the expected result.