golang 子类调用父类函数

前端之家收集整理的这篇文章主要介绍了golang 子类调用父类函数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
// testStruct project main.go
package main
 
import (
"fmt"
)
 
type A struct {
Text string
}
 
type Operator interface {
Say()
}
 
func (a *A) Say() {
fmt.Printf("A::Say():%s\n", a.Text)
}
 
type B struct {
A
}
 
func (b *B) Say() {
b.A.Say()
fmt.Printf("B::Say():%s\n", b.Text)
}
 
func main() {
b := B{}
b.Text = "hello,world"
b.Say()
}

A::Say():hello,world

B::Say():hello,world

原文链接:https://www.f2er.com/go/190204.html

猜你在找的Go相关文章