Complete the code to declare an interface named Speaker.
type Speaker interface {
[1]
}The interface method must include parentheses even if it has no parameters, so Speak() is correct.
Complete the code to make type Dog implement the Speaker interface.
type Dog struct {}
func (d Dog) [1] {
fmt.Println("Woof!")
}To implement the Speaker interface, Dog must have a method Speak() matching the interface method exactly.
Fix the error in the code to assign a Dog to a Speaker interface variable.
var s Speaker
var d Dog
s = [1]Since Dog implements Speaker by value receiver, assigning d directly works. Using &d would also work if the method had pointer receiver.
Fill both blanks to create a map of string keys to Speaker interface values, and add a Dog instance.
var animals = map[string][1]{} animals["dog"] = [2]
The map value type must be the interface Speaker. To add a Dog, use Dog{} which implements Speaker.
Fill all three blanks to define an interface, implement it with a Cat struct, and call the method.
type [1] interface { [2]() } type Cat struct {} func (c Cat) [2]() { fmt.Println("Meow!") } func main() { var s [1] = Cat{} s.[2]() }
The interface is named Speaker. The method is Speak(), but blanks expect only the method name Speak without parentheses. The method receiver and call use Speak.