Inheritance in Golang can be achieved by including anonymous structures in the structure. Specifically, for example, if the structure of iPhone needs to be inherited, the structure of phone can be written as follows:
package main
import "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)
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。