0
0
Goprogramming~10 mins

Interface definition in Go - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define an interface named Speaker.

Go
type Speaker [1] {
    Speak() string
}
Drag options to blanks, or click blank then click option'
Afunc
Bstruct
Cinterface
Dpackage
Attempts:
3 left
💡 Hint
Common Mistakes
Using struct instead of interface to define an interface.
Forgetting the keyword interface.
2fill in blank
medium

Complete the code to declare a method Speak() that returns a string in the interface.

Go
type Speaker interface {
    [1]() string
}
Drag options to blanks, or click blank then click option'
ASpeak
BListen
CSay
DTalk
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different method name than defined in the interface.
Adding parameters to the method when none are required.
3fill in blank
hard

Fix the error in the interface definition by completing the code.

Go
type [1] interface {
    Speak() string
}
Drag options to blanks, or click blank then click option'
ASpeaker
Bspeaker
CSpeakers
DSpeak
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase names for exported interfaces.
Using method names as interface names.
4fill in blank
hard

Fill both blanks to define an interface named Reader with a method Read that returns an int and an error.

Go
type [1] interface {
    [2]() (int, error)
}
Drag options to blanks, or click blank then click option'
AReader
BWriter
CRead
DWrite
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing interface and method names.
Incorrect method signature.
5fill in blank
hard

Fill all three blanks to define an interface named Writer with a method Write that takes a byte slice and returns an int and an error.

Go
type [1] interface {
    [2]([3] []byte) (int, error)
}
Drag options to blanks, or click blank then click option'
AWriter
BWrite
Cdata
DRead
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect method or parameter names.
Wrong parameter types.