Inheritance/Single: Difference between revisions
Content deleted Content added
{{omit from|PARI/GP}} |
Go solution |
||
Line 323:
end module anim
</lang>
=={{header|Go}}==
Go eschews most trappings of inheritance, yet it's anonymous field feature allows building one struct type upon another and accessing fields of "embedded" types without extra synax.
<lang go>package main
type animal struct {
alive bool
}
type dog struct {
animal
obedienceTrained bool
}
type cat struct {
animal
litterBoxTrained bool
}
type lab struct {
dog
color string
}
type collie struct {
dog
catchesFrisbee bool
}
func main() {
var pet lab
pet.alive = true
pet.obedienceTrained = false
pet.color = "yellow"
}
</lang>
|