type Person struct{
Id int
Name string}type Student struct{
Person
Name string}
s1.id =3
结构体方法定义
func(s Student)eat(){
fmt.Println("吃")}
方法继承
type Person struct{
id int}func(p Person)hello(){
fmt.Println("hello")}type Student struct{
Person
name string}func(s Student)eat(){
fmt.Println("吃")}var s3 Student
s3.eat()
s3.hello()
方法重写
type Person struct{
id int}func(p Person)hello(){
fmt.Println("hello")}type Student struct{
Person
name string}func(s Student)eat(){
fmt.Println("吃")}func(s Student)hello(){
fmt.Println("hi")}var s3 Student
s3.eat()
s3.hello()