Definition of structure and interface in Go

package main
import (
   "fmt"
)

//Define the interface
type woman interface {//Define a woman interface, define a love method
   love()
   makelove()
}
//Define a structure
type teacher struct {

   name string
   Age int
}
//Implement the interface
func (p *teacher)  love() {
   fmt.Println(p.Age,"gan")
}
//type human interface {
// //Only the declaration is not implemented and there is no type
// eat()
//}
//
//type Student struct {
// name string
//}
//
Implement interface methods
//func (s *Student) eat() {
// fmt.Println(s.name + " eat")
//}

func main() {
   //s := Student{"yy"}
   tt :=teacher{"Alice",18}
   //(&s).eat()
   (&tt).love()
}

Guess you like

Origin blog.csdn.net/zhuiyunzhugang/article/details/109586552