Can a struct contain methods?

  • No, a struct cannot contain methods
  • Yes, a struct can contain methods as associated functions
  • Yes, but only anonymous methods
  • Yes, but only predefined methods
In Go, a struct can contain methods as associated functions. These methods are defined with a receiver, which allows them to be called on instances of the struct type.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *