当前位置:网站首页>[yu gong series] Go program 035-08 2022 interfaces and inheritance and transformation and empty interface
[yu gong series] Go program 035-08 2022 interfaces and inheritance and transformation and empty interface
2022-08-11 03:20:00 【Yugong move code】
一、Interfaces and Inheritance and Conversion
package main
import "fmt"
type Humaner interface {
SayHello()
}
type Personer interface {
Humaner
Say()
}
type Student struct {
}
func (s *Student) SayHello() {
fmt.Println("大家好")
}
func (s *Student) Say() {
fmt.Println("你好")
}
func main() {
var stu Student
var per Personer
per = &stu
per.Say()
per.SayHello() // 可以调用所继承的接口中的方法.
var h Humaner
h = per
// per=h
h.SayHello()
}

继承就是子类继承父类的特征和行为,使得子类对象(实例)具有父类的实例域和方法,或子类从父类继承方法,使得子类具有父类相同的行为.
Interface inheritance is a concept from design patterns.接口继承,subtyping.Describes when an object can be used in place of another object.接口是一个抽象类型,是抽象方法的集合,接口通常以interface来声明.Interfaces can inherit multiple interfaces because interfaces only define behavior and do not contain the meaning of categories and do not refer to a specific kind of thing,
二、空接口
空接口(interface{})不包含任何的方法,正因为如此,所有的类型都实现了空接口,因此空接口可以存储任意类型的数值.
package main
import "fmt"
func main() {
var i interface{
}
i = 123
i = "abc"
fmt.Println(i)
var s []interface{
}
s = append(s, 123, "abc", 12.3)
for j := 0; j < len(s); j++ {
fmt.Println(s[j])
}
}

边栏推荐
- 【ADI低功耗2k代码】基于ADuCM4050的ADXL363、TMP75的加速度、温度检测及串口打印、蜂鸣器播放音乐(孤勇者)
- 论文精度 —— 2017 CVPR《High-Resolution Image Inpainting using Multi-Scale Neural Patch Synthesis》
- MongoDB 基础了解(二)
- AI+医疗:使用神经网络进行医学影像识别分析
- AI+医疗:使用神经网络进行医学影像识别分析
- pathman_config、pathman_config_params 删除后,如何重建?
- 用户如何克服程序化交易中的情绪问题?
- CSAPP Data Lab
- 【愚公系列】2022年08月 Go教学课程 036-类型断言
- C语言之自定义类型------结构体
猜你喜欢

CTO说MySQL单表行数不要超过2000w,为啥?

Ten Advanced Concepts of SQL Development

font

CSDN 博客更换皮肤

Detailed explanation of new features of ES advanced array function syntax

Vim and copy and paste from the outside (don't need to install the plugin)

"How to kick a bad habit to read notes?

阿里低代码框架 lowcode-engine 之自定义物料篇

The practice of alibaba data synchronization component canal

【愚公系列】2022年08月 Go教学课程 035-接口和继承和转换与空接口
随机推荐
watch监听
最倒霉与最幸运
Multi-merchant mall system function disassembly 26 lectures - platform-side distribution settings
重庆纸质发票再见!开住宿费电子发票即将全面取代酒店餐饮加油站发票
互换性测量与技术——偏差与公差的计算,公差图的绘制,配合与公差等级的选择方法
QueryDet:级联稀疏query加速高分辨率下的小目标检测
SQL 开发的十个高级概念
Redis老了吗?Redis与Dragonfly性能比较
Unity2D animation (1) introduction to Unity scheme - animation system composition and the function of use
DOM-DOM树,一个DOM树有三种类型的节点
The negative semantic transformation layer
输入起始位置,终止位置截取链表
【DB运营管理/开发解决方案】上海道宁为您提供提高工作便利性的集成开发工具——Orange
常用认证机制
“京台高铁”亮相百度地图,真能在2035年建成吗?
Getting Started with Raspberry Pi (5) System Backup
按摩椅控制板的开发让按摩椅变得简约智能
荣威imax8ev魔方电池安全感,背后隐藏着哪些黑化膨胀?
大马驮2石粮食,中马驮1石粮食,两头小马驮一石粮食,要用100匹马,驮100石粮食,如何分配?
Traversal of DOM tree-----modify styles, select elements, create and delete nodes