Golang的继承能够通过构造体外面蕴含匿名构造体实现,具体,比方iPhone这个构造体要继承法phone这个构造体能够这样写:
package mainimport "fmt"type phone struct { design_place string production_place string}type iphone struct { brand string phone}func main() { thePhone := phone{ design_place: "California", production_place: "China", } thisPhone := iphone{ brand: "Apple", phone: thePhone, } fmt.Println(thisPhone.production_place, thisPhone.brand)}