-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Expand file tree
/
Copy pathmain.go
More file actions
44 lines (38 loc) · 704 Bytes
/
Copy pathmain.go
File metadata and controls
44 lines (38 loc) · 704 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"fmt"
)
type person struct {
First string
Last string
Age int
}
type doubleZero struct {
person
First string
LicenseToKill bool
}
func main() {
p1 := doubleZero{
person: person{
First: "James",
Last: "Bond",
Age: 20,
},
First: "Double Zero Seven",
LicenseToKill: true,
}
p2 := doubleZero{
person: person{
First: "Miss",
Last: "MoneyPenny",
Age: 19,
},
First: "If looks could kill",
LicenseToKill: false,
}
// fields and methods of the inner-type are promoted to the outer-type
fmt.Println(p1.First, p1.person.First)
fmt.Println(p2.First, p2.person.First)
fmt.Println(p1.Last, p1.person.Last)
}