init commit
This commit is contained in:
36
archive/go/class/class.go
Normal file
36
archive/go/class/class.go
Normal file
@ -0,0 +1,36 @@
|
||||
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()
|
||||
}
|
Reference in New Issue
Block a user