Complete the code to declare an interface named Speaker.
type Speaker interface {
[1]()
}The interface Speaker requires a method named Speak with no parameters.
Complete the code to make type Dog satisfy the Speaker interface by implementing Speak method.
package main import "fmt" type Dog struct {} func (d Dog) [1]() { fmt.Println("Woof!") }
The method Speak is required to satisfy the Speaker interface.
Fix the error in the code to make type Cat satisfy the Speaker interface.
package main import "fmt" type Cat struct {} func (c Cat) [1]() { fmt.Println("Meow!") }
The method Speak must have the same signature as in the interface. Here it returns nothing, which is acceptable if the interface method has no return.
Fill both blanks to declare an interface and a type that satisfies it.
type [1] interface { [2]() } type Bird struct {} func (b Bird) [2]() { fmt.Println("Tweet!") }
The interface is named Singer and requires a method Speak. The type Bird implements Speak to satisfy the interface.
Fill all three blanks to create a function that accepts any Speaker and calls its Speak method.
func [1](s [2]) { s.[3]() }
The function MakeSound takes a parameter of type Speaker interface and calls its Speak method.