Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
31
Task/Inheritance-Multiple/Go/inheritance-multiple-1.go
Normal file
31
Task/Inheritance-Multiple/Go/inheritance-multiple-1.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
// Example of composition of anonymous structs
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Two ordinary structs
|
||||
type camera struct {
|
||||
optics, sensor string
|
||||
}
|
||||
|
||||
type mobilePhone struct {
|
||||
sim, firmware string
|
||||
}
|
||||
|
||||
// Fields are anonymous because only the type is listed.
|
||||
// Also called an embedded field.
|
||||
type cameraPhone struct {
|
||||
camera
|
||||
mobilePhone
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Struct literals must still reflect the nested structure
|
||||
htc := cameraPhone{camera{optics: "zoom"}, mobilePhone{firmware: "3.14"}}
|
||||
|
||||
// But fields of anonymous structs can be referenced without qualification.
|
||||
// This provides some effect of the two parent structs being merged, as
|
||||
// with multiple inheritance in some other programming languages.
|
||||
htc.sim = "XYZ"
|
||||
fmt.Println(htc)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue