go语言通过组合实现继承
type B struct {
A
}
package main
import "fmt"
type A struct{
F1 int
}
type B struct {
A
}
func (this *A)fun1(){
fmt.Println("fun1:a")
}
func (this *A)fun2(){
fmt.Println("fun2:a")
}
func (this *B)fun2(){
fmt.Println("fun2:b")
}
func main(){
b:=B{}
b.F1=100
fmt.Println(b.A.F1)
fmt.Println(b.F1)
b.fun1()//调用A,继承
b.fun2() //调用B,重写
}