Last active
August 15, 2018 17:02
-
-
Save PeteGabriel/cd77c5446e7d6e5ea874b0d9ac34066a to your computer and use it in GitHub Desktop.
Example of method calls in GO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
func main() { | |
//Declare a pointer of type Human | |
peter := new(Human) | |
//The compile will dereference the pointer to make the call | |
peter.sayHello() | |
} | |
//custom defined interface | |
type Person interface { | |
sayHello() | |
} | |
//custom defined type | |
type Human struct {} | |
//Human type implements Person interface | |
func (p *Human) sayHello() { fmt.Println("Hello") } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment