编程语言-go:类与对象的概念

go中没有类和对象的概念,只有struct和变量与之对应

1,定义“类”: struct

type Books struct{
           title string
           author string
           id int
 }

2, 创建“对象”: 变量

 var book1 Books
 book1.title="go-languange"
 book1.author="wang"
 book1.id=101

 var book3 =Books{"bookxxx","personxxx",201}
 var book4=Books{author:"author2",id:222}

整体代码如下:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/eyeofeagle/article/details/86563157