test

博客园 首页 新随笔 联系 订阅 管理
package main

import (
"fmt"
)

const (
URL = "http://www.163.com"
UID = "admin"
TOKEN = "123456"
)

type Ren struct {
Phone string
}

type Student struct {
Ren
Name string
Age int
}
type Teacher struct {
Ren
Name string
Age int
}

func main() {
a := Student{
Ren: Ren{Phone: "18532105052"},
Name: "test1",
Age: 12,
}
b := Student{
Ren: Ren{Phone: "18582105055"},
Name: "kkk2",
Age: 13,
}

fmt.Println(a, b)
}

 

 

结构定义方法

type Teacher struct {
    Name string
    Age  int
}

func main() {
    c := Teacher{}
    c.Say()
}

func (t Teacher) Say() {
    fmt.Println("say test test!")
}

 

posted on 2017-04-26 15:05  testgogogo  阅读(450)  评论(0)    收藏  举报