7

【笔记】Go语言的面向对象

 1 year ago
source link: https://loli.fj.cn/2023/04/05/Go%E8%AF%AD%E8%A8%80%E7%9A%84%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

【笔记】Go语言的面向对象

Go语言的面向对象学习笔记

  • 通过匿名字段实现继承操作
  • 将父类结构体名称作为子类结构体成员属性
type Father struct {
name string
}

type Son struct {
Father
}

func main() {
// 在构造时为子类继承得到的父类的属性赋值
var son Son = Son{Father{""}}
// 直接为子类继承得到的父类的属性赋值
var son Son
son.name = ""
// 在子类为继承得的父类的属性赋值
var son Son
son.Father.name = ""
}

哔哩哔哩——喔咔咔耶耶


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK