Update 2.5.md
This commit is contained in:
6
2.5.md
6
2.5.md
@@ -271,8 +271,8 @@ method的语法如下:
|
|||||||
sam.SayHi()
|
sam.SayHi()
|
||||||
}
|
}
|
||||||
|
|
||||||
### method重载
|
### method重写
|
||||||
上面的例子中,如果Emplyee想要实现自己的SayHi,怎么办?简单,和匿名字段冲突一样的道理,我们可以在Emplyee上面定义一个method,重载了匿名字段的方法。请看下面的例子
|
上面的例子中,如果Emplyee想要实现自己的SayHi,怎么办?简单,和匿名字段冲突一样的道理,我们可以在Emplyee上面定义一个method,重写了匿名字段的方法。请看下面的例子
|
||||||
|
|
||||||
package main
|
package main
|
||||||
import "fmt"
|
import "fmt"
|
||||||
@@ -298,7 +298,7 @@ method的语法如下:
|
|||||||
fmt.Printf("Hi, I am %s you can call me on %s\n", h.name, h.phone)
|
fmt.Printf("Hi, I am %s you can call me on %s\n", h.name, h.phone)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Employee的method重载Human的method
|
//Employee的method重写Human的method
|
||||||
func (e *Employee) SayHi() {
|
func (e *Employee) SayHi() {
|
||||||
fmt.Printf("Hi, I am %s, I work at %s. Call me on %s\n", e.name,
|
fmt.Printf("Hi, I am %s, I work at %s. Call me on %s\n", e.name,
|
||||||
e.company, e.phone) //Yes you can split into 2 lines here.
|
e.company, e.phone) //Yes you can split into 2 lines here.
|
||||||
|
|||||||
Reference in New Issue
Block a user