Files
2026-03-02 13:50:35 +01:00

41 lines
626 B
Go

package main
import (
"fmt"
)
type base struct {
num int
}
func (b base) describe() string {
return fmt.Sprintf("base with num=%v", b.num)
}
type container struct {
base
str string
}
func main() {
co := container{
base: base{
num: 1,
},
str: "Some name",
}
fmt.Printf("co={num: %v, str: %v}\n", co.num, co.str)
fmt.Println("also num: ", co.base.num) // also num but can be without
// co can also use base method describe since it emebeds base
fmt.Println("describe: ", co.describe())
var d describer = co
fmt.Println("describer:", d.describe())
}
type describer interface {
describe() string
}