Create a Go program to demonstrate the use of an interface to handle multiple struct types.
MediumProblem Statement
Create a Go program to demonstrate the use of an interface to handle multiple struct types.
Sample Input
Two structs Dog and Cat implementing a method Speak.
Sample Output
Woof! Meow!
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
package main
import "fmt"
type Animal interface {
Speak() string
}
func printSpeak(animal Animal) {
// Print the message from the Speak method
}
func main() {
// Implement the interface and call the Speak method for different types
}
Input
Two structs Dog and Cat implementing a method Speak.
Expected Output
Woof! Meow!