Code
go
package main
import "fmt"
type Base struct {
ID int
}
func (b Base) Describe() string {
return fmt.Sprintf("Base#%d", b.ID)
}
type User struct {
Base // Anonymous embedding
Name string
Age int
}
func main() {
u := User{
Base: Base{ID: 1},
Name: "Alice",
Age: 30,
}
fmt.Println(u.ID) // Directly access embedded field
fmt.Println(u.Describe()) // Call embedded method
fmt.Println(u.Name)
}