摘要:1 package main 2 3 import "fmt" 4 5 type A interface { 6 test1() 7 } 8 9 type B interface { 10 test2() 11 } 12 13 type C interface { 14 A 15 B 16 test
阅读全文
摘要:1 package main 2 3 import ( 4 "fmt" 5 "math" 6 ) 7 8 // 1.定义一个接口 9 type Shape interface { 10 peri() float64 // 形状的周长 11 area() float64 // 形状的面积 12 } 1
阅读全文
摘要:1 package main 2 3 import "fmt" 4 5 // 空接口 6 type A interface{} 7 8 type Cat struct { 9 color string 10 } 11 12 type Person struct { 13 name string 14
阅读全文
摘要:1 package main 2 3 import "fmt" 4 5 // 1.定义接口 6 type USB interface { 7 start() //USB设备开始工作 8 end() //USB设备结束工作 9 } 10 11 // 2.实现类 12 type Mouse struct
阅读全文
摘要:1 package main 2 3 import "fmt" 4 5 // 1.定义一个"父类" 6 type Person struct { 7 name string 8 age int 9 } 10 11 // 2.定义一个"子类" 12 type Student struct { 13 P
阅读全文
摘要:1 package main 2 3 import "fmt" 4 5 //1.定义一个工人结构体 6 type Worker struct { 7 name string 8 age int 9 sex string 10 } 11 12 type Cat struct { 13 color st
阅读全文
摘要:1 package main 2 3 import "fmt" 4 5 // 1.定义父类 6 type Person struct { 7 name string 8 age int 9 } 10 11 // 2.定义子类 12 type Student struct { 13 Person //
阅读全文
摘要:package main import "fmt" // 1.定义一个书的结构体 type Book struct { bookName string price float64 } // 2.定义学生的结构体 type Student struct { name string age int bo
阅读全文
摘要:1 package main 2 3 import "fmt" 4 5 type Student struct { 6 name string 7 age int 8 } 9 10 type Worker struct { 11 string // 匿名字段 12 int // 匿名字段,默认使用数
阅读全文
摘要:1 package main 2 3 import "fmt" 4 5 type Person struct { 6 name string 7 age int 8 sex string 9 address string 10 } 11 12 func main() { 13 /* 14 数据类型:
阅读全文
摘要:1 package main 2 3 import "fmt" 4 5 // 定义结构体 6 type Person struct { 7 name string 8 age int 9 sex string 10 address string 11 } 12 13 func main() { 14
阅读全文
摘要:1 package main 2 3 import "fmt" 4 5 func fun1(num int) { // 值传递:num = a = 10 6 fmt.Println("fun1()函数中,num的值:", num) 7 num = 100 8 fmt.Println("fun1()函
阅读全文
摘要:1 package main 2 3 import "fmt" 4 5 func fun1() { 6 fmt.Println("fun1().....") 7 } 8 9 // 普通函数 10 func fun2() [4]int { 11 arr := [4]int{1, 2, 3, 4} 12
阅读全文
摘要:1 package main 2 3 import "fmt" 4 5 func main() { 6 /* 7 数组指针:首先是一个指针,一个数组的地址。 8 *[4]Type 9 10 指针数组:首先是一个数组,存储的数据类型是指针 11 [4]*Type 12 13 14 *[5]float6
阅读全文
摘要:1 package main 2 3 import "fmt" 4 5 func main() { 6 /* 7 指针:pointer 8 存储了另一个变量的内存地址的变量。 9 10 */ 11 12 // 1.定义一个int类型的变量 13 a := 10 14 fmt.Println("a的数
阅读全文
摘要:1 package main 2 3 import "fmt" 4 5 func main() { 6 /* 7 Go语言的数据类型: 8 9 数值类型:整数,浮点 10 进行运算操作,加减乘除,打印 11 字符串: 12 可以获取单个字符,截取子串,遍历,strings包下的函数操作。。 13 数
阅读全文
摘要:1 package main 2 3 import "fmt" 4 5 func fun1() {} 6 7 func fun2(a int) int { 8 return 0 9 } 10 11 func fun3(a float64, b, c int) (int, int) { 12 retu
阅读全文
摘要:1 package main 2 3 import "fmt" 4 5 func getSum(n int) int { 6 fmt.Println("**********") 7 if n == 1 { 8 return 1 9 } 10 return getSum(n-1) + n 11 } 1
阅读全文
摘要:1 package main 2 3 import "fmt" 4 5 func fun2(s2 []int) { 6 fmt.Println("函数中,切片的数据:", s2) // [1 2 3 4] 7 s2[0] = 100 8 fmt.Println("函数中,切片的数据更改后:", s2
阅读全文
摘要:1 package main 2 3 import ( 4 "fmt" 5 "strconv" 6 ) 7 8 func main() { 9 /* 10 strconv包:字符串和基本类型之前的转换 11 string convert 12 */ 13 14 // fmt.Println("aa"
阅读全文