forked from steger/pr3-ws202526
struct embedding
parent
71fc88cae3
commit
50eb088f8a
|
|
@ -0,0 +1,40 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
type Person struct {
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Person) Say() {
|
||||||
|
fmt.Println("Hi, my name is", p.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Student struct {
|
||||||
|
Person
|
||||||
|
Semester int
|
||||||
|
}
|
||||||
|
|
||||||
|
type Teacher struct {
|
||||||
|
Person
|
||||||
|
Subject string
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
|
||||||
|
max := Person{"Max"}
|
||||||
|
|
||||||
|
daniel := Student{Person{"Daniel"}, 3}
|
||||||
|
|
||||||
|
sebastian := Teacher{Person{"Sebastian"}, "PR3"}
|
||||||
|
|
||||||
|
max.Say()
|
||||||
|
|
||||||
|
daniel.Say()
|
||||||
|
|
||||||
|
sebastian.Say()
|
||||||
|
|
||||||
|
max = sebastian.Person
|
||||||
|
|
||||||
|
max.Say()
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue