golang go_oop3.go

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了golang go_oop3.go相关的知识,希望对你有一定的参考价值。

// Go’s syntax is very much like C, you should be fine 
// reading it.

// Defining Human type, it has a variable Name of type string. 
// (Yes, type is mentioned after variable name)
type Human struct {
     Name string
}

// Defining a method GetName on the type Human which 
// returns a string.
func (h Human) GetName() string {
     return h.Name
}

// Human struct is embedded within Student, this is not 
// inheritance but composition. Composition can also be done
// in a usual way by creating a Human type variable but there
// are few advantages to using struct embedding.
type Student struct {
    id int
    Human
}

human := Human{"John"} // type is implicit
student := Student{human, 1}

// you can actually do the following, even though getName() is
// Human's method.
student.GetName()

【golang】解决etcd安装出现的问题

参考技术A 解决办法修改依赖版本:

在GOPATH/src下执行

在go mod里加入

以上是关于golang go_oop3.go的主要内容,如果未能解决你的问题,请参考以下文章

java go_oop3.java

java go_oop1.java

golang核心编程

golang核心编程

Golang 基础

Golang zip 压缩与解压