Skip to content

Instantly share code, notes, and snippets.

@afrinjamanbd
Created January 20, 2021 11:13
Show Gist options
  • Save afrinjamanbd/a516ffaf3f887fb4772cc11949c5a157 to your computer and use it in GitHub Desktop.
Save afrinjamanbd/a516ffaf3f887fb4772cc11949c5a157 to your computer and use it in GitHub Desktop.
This piece of code shows inheritance in golang.
package main
import (
"fmt"
)
type Animal struct{
Name string
Tail bool
Leg int
}
type Dog struct{
Animal
Bark bool
}
func main() {
Animalobj:= Animal{
Name: "Chicken",
Tail: false,
Leg: 2,
}
fmt.Println("Animal name is", Animalobj.Name, "\nTotal leg", Animalobj.Leg, "\nHas Tail =", Animalobj.Tail)
Dogobj:= Dog{
Animal: Animal{
Name: "Dog",
Tail: true,
Leg: 4,
},
Bark: true,
}
fmt.Println("\n\nAnimal name is", Dogobj.Name, "\nTotal leg", Dogobj.Leg, "\nHas Tail =", Dogobj.Tail, "\nBarks =", Dogobj.Bark)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment