Go言語 構造体

package main

import "fmt"

type studentType struct {
    name string
    score scoreType
}

type scoreType struct {
    subject string
    points int
}

func (s scoreType) isPassed() bool {
    if s.points >= 70 {
        return true
    } else {
        return false
    }
}

func main() {
    taro := studentType{
        name:  "Taro",
        score: scoreType{
            subject: "Math",
            points:  85,
        },
    }

    fmt.Println(taro.name)
    fmt.Println(taro.score.subject)
    fmt.Println(taro.score.points)
    fmt.Println(taro.score.isPassed())
}

投稿者: chosuke

趣味はゲームやアニメや漫画などです

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です