Last active
August 29, 2015 14:04
-
-
Save zgiber/d109cf2c64e042caa300 to your computer and use it in GitHub Desktop.
go "inheritance" syntax reminder
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" | |
) | |
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