Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Create a Go program to demonstrate the use of an interface to handle multiple struct types.

Medium

Problem 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 }
Log in or sign up to run or submit your code.Log inSign up
Input
Two structs Dog and Cat implementing a method Speak.
Expected Output
Woof!
Meow!