2
1
Fork 0

struct embedding

main
Sebastian Steger 2025-08-20 07:04:05 +00:00
parent 9f194ed185
commit 37312f864c
1 changed files with 40 additions and 0 deletions

View File

@ -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()
}