Complete the code to declare that type Dog implements the Speaker interface.
type Speaker interface {
Speak() string
}
type Dog struct {}
func (d Dog) [1]() string {
return "Woof!"
}The method name must exactly match the interface method name Speak to implement the interface.
Complete the code to create a variable of type Speaker and assign a Dog value to it.
var s Speaker = [1]{}Dog implements Speaker, so we can assign a Dog value to a Speaker variable.
Fix the error in the method receiver to correctly implement the Speaker interface.
func (d *Dog) [1]() string { return "Woof!" }
The method name must be Speak to implement the Speaker interface.
Fill both blanks to define a Cat type that implements Speaker with a pointer receiver.
type Cat struct {}
func ([1] *Cat) [2]() string {
return "Meow!"
}The receiver variable is usually a short name like c, and the method name must be Speak to implement the interface.
Fill all three blanks to create a function that accepts a Speaker and calls its Speak method.
func saySomething([1] [2]) string { return [1].[3]() }
The function parameter name is s, its type is Speaker, and we call s.Speak() to get the string.