当前位置:网站首页>[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])
}
}
边栏推荐
- 【Unity入门计划】Unity2D动画(1)-动画系统的组成及功能的使用
- 怎么删除语句审计日志?
- I didn't expect MySQL to ask these...
- 深度学习-第二次
- Environment configuration of ESP32 (arduino arduino2.0 VScode platform which is easy to use?)
- A surviving spouse of the opposite sex within large turn paragraph, what for
- [Pdf generated automatically bookmarks]
- 论文精度 —— 2017 CVPR《High-Resolution Image Inpainting using Multi-Scale Neural Patch Synthesis》
- "Life Is Like First Seen" is ill-fated, full of characters, and the contrast of Zhu Yawen's characters is too surprising
- (Nips-2015)空间变换器网络
猜你喜欢
电商项目——商城限时秒杀功能系统
Redis老了吗?Redis与Dragonfly性能比较
flink The object probably contains or references non serializable fields.
The problem that Merge will be lost again after code Revert has been solved
浮点数在内存中的存储方式
图解LeetCode——640. 求解方程(难度:中等)
ES6 advanced string processing new features
leetcode: 358. Reorder strings at K distance intervals
STC8H开发(十五): GPIO驱动Ci24R1无线模块
Detailed explanation of new features of ES advanced array function syntax
随机推荐
A Practical Arrangement of Map GIS Development Matters (Part 1)
Economic Misunderstandings in the Crypto World: Is Cash a Savings?Scarcity creates value?
【愚公系列】2022年08月 Go教学课程 036-类型断言
MongoDB 基础了解(二)
EasyCVR接入海康大华设备选择其它集群服务器时,通道ServerID错误该如何解决?
ESP32的环境配置(arduino arduino2.0 VScode platform哪个好用?)
How does MSP430 download programs to the board?(IAR MSPFET CCS)
《人生若如初见》命运多舛,人物饱满,朱亚文角色反差太惊喜
【LeetCode】Day112-重复的DNA序列
LeetCode Hot Questions (12. The Best Time to Buy and Sell Stocks)
Multi-threaded ThreadPoolExecutor
Docker 链接sqlserver时出现en-us is an invalid culture错误解决方案
基于FPGA状态机的自动售货机功能实现
论文精度 —— 2017 CVPR《High-Resolution Image Inpainting using Multi-Scale Neural Patch Synthesis》
AI+Medical: Using Neural Networks for Medical Image Recognition and Analysis
Qnet弱网测试工具操作指南
Goodbye Chengdu paper invoices!The issuance of electronic invoices for accommodation expenses will soon completely replace the invoices of hotels, catering and gas stations
font
【LeetCode】Day112-repetitive DNA sequence
oracle的基数会影响到查询速度吗?