blog/archive/go/class/class.go
2024-03-19 02:45:09 +08:00

37 lines
403 B
Go

package main
import "fmt"
type IA interface {
FuncA()
FuncB()
}
type A struct {
IA
}
func (a *A) FuncA() {
fmt.Println("class a,func a")
}
type B struct {
}
func (b *B) FuncA() {
fmt.Println("class b,func a")
}
func (b *B) FuncB() {
fmt.Println("class b,func b")
}
func main() {
var a IA = new(A)
a.FuncA()
// a.FuncB() //报错的
var a2 IA = &A{IA: new(B)}
a2.FuncA()
a2.FuncB()
}