OOP实例:
// OOP project main.go
package main
import (
"fmt"
)
type people interface {
Count(a int, b int) int
Max(a int, b int) int
}
type abc struct {
}
func (ab abc) Count(a int, b int) int {
return a + b
}
func (ab abc) Max(a int, b int) int {
var s int
if a > b {
s = a
} else {
s = b
}
return s
}
func main() {
var a1 people = new(abc)
fmt.Println(a1.Count(1, 2))
fmt.Println(a1.Max(1, 2))
}
go的接口实现
最新推荐文章于 2024-10-15 15:57:34 发布