package main import ( "fmt" ) // Definir o tipo de interface woman interface {// Definir a interface de uma mulher, definir um método de amor love () makelove () } // Definir um tipo de estrutura professor struct { name string Age int } / / Implementar a interface func (p * teacher) love () { fmt.Println (p.Age, "gan") } // digite a interface humana { // // Apenas a declaração não é implementada e não há nenhum tipo / / eat () //} // // type Student struct { // name string //} // Implementa o método de interface // func (s * Student) eat () { // fmt.Println (s.name + "comer") //} func main () { // s: = Aluno {"yy"} tt: = professor {"Alice", 18} // (& s) .eat () (& tt) .love () }
Definição de estrutura e interface em Go
Acho que você gosta
Origin blog.csdn.net/zhuiyunzhugang/article/details/109586552
Recomendado
Clasificación