fix speciality to specialty
This commit is contained in:
18
en/02.4.md
18
en/02.4.md
@@ -105,7 +105,7 @@ Let's see one example.
|
||||
|
||||
type Student struct {
|
||||
Human // embedded field, it means Student struct includes all fields that Human has.
|
||||
speciality string
|
||||
specialty string
|
||||
}
|
||||
|
||||
func main() {
|
||||
@@ -116,11 +116,11 @@ Let's see one example.
|
||||
fmt.Println("His name is ", mark.name)
|
||||
fmt.Println("His age is ", mark.age)
|
||||
fmt.Println("His weight is ", mark.weight)
|
||||
fmt.Println("His speciality is ", mark.speciality)
|
||||
fmt.Println("His specialty is ", mark.specialty)
|
||||
// modify notes
|
||||
mark.speciality = "AI"
|
||||
fmt.Println("Mark changed his speciality")
|
||||
fmt.Println("His speciality is ", mark.speciality)
|
||||
mark.specialty = "AI"
|
||||
fmt.Println("Mark changed his specialty")
|
||||
fmt.Println("His specialty is ", mark.specialty)
|
||||
// modify age
|
||||
fmt.Println("Mark become old")
|
||||
mark.age = 46
|
||||
@@ -157,17 +157,17 @@ All the types in Go can be used as embedded fields.
|
||||
Human // struct as embedded field
|
||||
Skills // string slice as embedded field
|
||||
int // built-in type as embedded field
|
||||
speciality string
|
||||
specialty string
|
||||
}
|
||||
|
||||
func main() {
|
||||
// initialize Student Jane
|
||||
jane := Student{Human:Human{"Jane", 35, 100}, speciality:"Biology"}
|
||||
jane := Student{Human:Human{"Jane", 35, 100}, specialty:"Biology"}
|
||||
// access fields
|
||||
fmt.Println("Her name is ", jane.name)
|
||||
fmt.Println("Her age is ", jane.age)
|
||||
fmt.Println("Her weight is ", jane.weight)
|
||||
fmt.Println("Her speciality is ", jane.speciality)
|
||||
fmt.Println("Her specialty is ", jane.specialty)
|
||||
// modify value of skill field
|
||||
jane.Skills = []string{"anatomy"}
|
||||
fmt.Println("Her skills are ", jane.Skills)
|
||||
@@ -196,7 +196,7 @@ Go use a very simple way to solve it. The outer fields get upper access levels,
|
||||
|
||||
type Employee struct {
|
||||
Human // embedded field Human
|
||||
speciality string
|
||||
specialty string
|
||||
phone string // phone in employee
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user