Go语言入门(一)——接口的实现

来源:互联网 发布:电脑淘宝详情页打不开 编辑:程序博客网 时间:2024/04/28 08:37
package mainimport (    "fmt")/*接口*/type IFly interface {    Fly()}/*Bird结构体*/type Bird struct {}/*接口方法的实现*/func (b *Bird) Fly() {    fmt.Println("Bird can fly")}/*Duck结构体*/type Duck struct {}/*接口方法的实现*/func (d *Duck) Fly() {    fmt.Println("Duck can not fly")}func main() {    b := new(Bird)    b.Fly()    d := new(Duck)    d.Fly()}

输出结果

0 0