码迷,mamicode.com
首页 > 其他好文 > 详细

golang对象

时间:2017-11-15 10:53:34      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:print   struct   lang   package   str   组合   type   highlight   pac   

对象和组合

package main
import (
"fmt"

)

type father struct {
name string
sex int
}
type sun struct {
father
age int
}
func main() {
m:=father{name:"father",sex:11}
s:=sun{father:father{name:"son",sex:12},age:14}
fmt.Println(s)
fmt.Println("name",s.name)
fmt.Println("name",m.name)
fmt.Println("sex",s.sex)
fmt.Println("sex",m.sex)
fmt.Println("age",s.age)
}

  

golang对象

标签:print   struct   lang   package   str   组合   type   highlight   pac   

原文地址:http://www.cnblogs.com/peterinblog/p/7837418.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!