Skip to content

Instantly share code, notes, and snippets.

@zgiber
Last active August 29, 2015 14:04
Show Gist options
  • Save zgiber/d109cf2c64e042caa300 to your computer and use it in GitHub Desktop.
Save zgiber/d109cf2c64e042caa300 to your computer and use it in GitHub Desktop.
go "inheritance" syntax reminder
package main
import (
"fmt"
)
type car struct {
wheels int
}
func (self *car) run() {
fmt.Println("I'm a normal car with", self.wheels, "wheels")
}
type sportCar struct {
car
coolness int
}
func (self *sportCar) run() {
fmt.Printf("I'm a sport car with %v wheels, but I'm %v%% cool. \n", self.wheels, self.coolness)
}
func main() {
normalCar := car{wheels: 4}
coolCar := sportCar{car: car{wheels: 4}, coolness: 100}
normalCar.run()
coolCar.run()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment