Skip to content

Instantly share code, notes, and snippets.

@aquilax
Created March 1, 2012 04:44
Show Gist options
  • Save aquilax/1947335 to your computer and use it in GitHub Desktop.
Save aquilax/1947335 to your computer and use it in GitHub Desktop.
Go inherit
package main
import (
"fmt"
)
type Parent struct {
name string
}
//Child inherits Parent's "properties" and "methods"
type Child struct {
Parent
}
func (p *Parent) PrintName() {
fmt.Println(p.name)
}
func (p *Parent) SetName(name string) {
p.name = name
}
func main() {
c := Child{}
c.SetName("Hi")
c.PrintName()
c.name = "Fi"
c.PrintName()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment