Go语言(二) 继承和重载
2024-08-26 00:34:02
继承
package main import "fmt" type Skills []string type person struct {
name string
age int
weight int
} type Student struct {
person //继承
Skills
int
spe string
} func init() { } func main() {
xuxu := Student{person{"xuxu",,}, []string{"anatomy"}, , "boy"} //方式一,全部指定
jane := Student{person:person{"Jane",,}, spe:"Biology"} //方式二,指哪打哪 fmt.Printf("His name is %s\n", jane.name)
fmt.Printf("His name is %s\n", xuxu.name)
}
重载
package main import "fmt" type Skills []string type person struct {
name string
age int
weight int
spe string //inner spe,重载
} type Student struct {
person //继承
Skills
int
spe string //outter spe,重载
} func init() { } func main() {
xuxu := Student{person{"xuxu",,,"inner spe"}, []string{"anatomy"}, , "outter spe"} fmt.Printf("His name is %s\n, inner spe :%, outter spe :%s", xuxu.name, xuxu.person.spe, xuxu.spe)
}
最新文章
- Grunt_1从安装开始创建一个基本的Grunt
- hdu 5877 (dfs+树状数组) Weak Pair
- Walkway.js – 用线条制作简约的 SVG 动画
- [转]轻松学习Ionic (四) 修改应用图标及添加启动画面(更新官方命令行工具自动生成)
- Laravel
- Android之Activity与Service通信
- 功能分解——Android下画分时图与k线图有感
- 使用struct实现面向对象编程的封装
- Hibernate Cascade &; Inverse
- 新闻公布系统 (Asp.net 三层架构 )
- linux dd命令
- UML之包图
- 协议形式化分析Scyther 资料整理
- Linux进程的实际用户ID和有效用户ID
- nginx thinkphp只能访问首页
- 用virtualenv建立独立虚拟环境 批量导入模块信息
- Hdu 4622 Reincarnation(后缀自动机)
- httpd-2.4.6
- LeetCode 9. Palindrome Number(回文数)
- win7(x64)安装scrapy框架
热门文章
- Ubuntu14.04下编译安装或apt-get方式安装搭建Apache或Httpd服务(图文详解)
- weblogic JDBC Connection Pools--转官方文档
- nginx基本配置说明
- JavaScript中的异步 macrotask 和 microtask
- 架构实战项目心得(四):使用Nexus配置Maven私有仓库
- [转]Using MVC 6 And AngularJS 2 With .NET Core
- pm2在node中的应用
- SQL语句表处理
- Cheatsheet: 2017 04.01 ~ 04.30
- Effective C++ .08 别让异常逃离析构函数