• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Go语言(二)继承和重载

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

继承

 1 package main
 2 
 3 import "fmt"
 4 
 5 type Skills  []string
 6 
 7 type person struct {
 8   name string
 9   age  int
10   weight int
11 }
12 
13 type Student struct {
14   person    //继承
15   Skills
16   int
17   spe string
18 }
19 
20 func init() {
21 
22 }
23 
24 func main() {
25   xuxu := Student{person{"xuxu",25,68}, []string{"anatomy"}, 1, "boy"} //方式一,全部指定
26   jane := Student{person:person{"Jane",25,100}, spe:"Biology"}  //方式二,指哪打哪
27 
28   fmt.Printf("His name is %s\n", jane.name)
29   fmt.Printf("His name is %s\n", xuxu.name)
30 }

 

 

重载

 1 package main
 2 
 3 import "fmt"
 4 
 5 type Skills  []string
 6 
 7 type person struct {
 8   name string
 9   age  int
10   weight int
11   spe  string  //inner spe,重载
12 }
13 
14 type Student struct {
15   person    //继承
16   Skills
17   int
18   spe string   //outter spe,重载
19 }
20 
21 func init() {
22 
23 }
24 
25 func main() {
26   xuxu := Student{person{"xuxu",25,68,"inner spe"}, []string{"anatomy"}, 1, "outter spe"} 
27 
28   fmt.Printf("His name is %s\n, inner spe :%, outter spe :%s", xuxu.name, xuxu.person.spe, xuxu.spe)
29 }

 

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
linux/mac下go环境变量配置发布时间:2022-07-10
下一篇:
go标准库的学习-database/sql/driver发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap